Advertisement
hocikto19

project migration

Jun 29th, 2016
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.45 KB | None | 0 0
  1. class CreateProjects < ActiveRecord::Migration
  2.   def up
  3.     create_table :projects do |t|
  4.       t.boolean :enabled
  5.       t.integer :rating
  6.       t.integer :seen_count
  7.       t.integer :saved_count
  8.       t.integer :replied_count
  9.       t.string :name
  10.       t.text :description
  11.       t.integer :identification
  12.       t.integer :price_from
  13.       t.integer :price_to
  14.       t.integer :area_from
  15.       t.integer :area_to
  16.       t.integer :rooms_from
  17.       t.integer :rooms_to
  18.  
  19.       t.timestamps null: false
  20.     end
  21.  
  22.     execute <<-SQL
  23.       CREATE TYPE offer_type AS ENUM ('sale', 'rent', 'purchase', 'sublease');
  24.       CREATE TYPE project_state AS ENUM ('in_preparation', 'under_construction', 'finished', 'approved');
  25.       CREATE TYPE standard AS ENUM ('standard', 'higher_standard', 'bare');
  26.       CREATE TYPE construction AS ENUM ('reinforced_concrete', 'brick', 'reinforced_concrete_with_brick', 'itong', 'straw', 'ceramics', 'wood', 'mounted_wood');
  27.     SQL
  28.  
  29.     add_column :projects, :offer_type_code, :offer_type, index: true
  30.     add_column :projects, :project_state_code, :project_state, index: true
  31.     add_column :projects, :standard_code, :standard, index: true
  32.     add_column :projects, :construction_code, :construction, index: true
  33.  
  34.   end
  35.  
  36.   def down
  37.     execute <<-SQL
  38.       DROP TYPE offer_type;
  39.       DROP TYPE project_state;
  40.       DROP TYPE standard;
  41.       DROP TYPE construction;
  42.     SQL
  43.     drop_table :projects
  44.   end
  45.  
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement