Equivalent scrapbook

…note on Migration


#migration for polymorphic table

class CreateAddressesTable < ActiveRecord::Migration
  def change
    create_table :addresses do |t|
      t.references :addressable, :polymorphic => true
      t.string :postcode
      t.timestamps
    end
  end
end

#will create:
Address(id: integer, addressable_id: integer, addressable_type: string,...)

#join index in polymorphic table

class CreateIndexForAddressesTable < ActiveRecord::Migration
  def self.up
    add_index :addresses, [:addressable_type, :addressable_id],:unique => true
  end

  def self.down
    remove_index :addresses, [:addressable_type, :addressable_id]
  end
end









rails generate scaffold game name:string       
rails g scaffold game name:string  --no-stylesheet
rails g scaffold --help                        
rails g migration add_vanity_name_to_user  vanity_name:string


add_column :table_name, :column_name, :column_type, {column_options}
add_column :users, :admin, :boolean, :default => false

add_column :accounts, :ssl_enabled, :integer, :default => 1
remove_column :table_name, :column_name

class AddSystemSettings < ActiveRecord::Migration
  def up
    create_table :system_settings do |t|
      t.string  :name
      t.string  :label
      t.boolean :valid
      t.text  :value
      t.string  :type
      t.integer  :position
      t.timestamps
    end

    SystemSetting.create  :name => "notice",
                          :label => "Use notice?",
                          :value => 1
  end

  def down
    drop_table :system_settings
  end
end

rake --task     # display most of the avalible rake tasks
rake db:reset   #will reset databse
db:migrate:rollback STEP=3