Download - Migrations in Rails 2.0
create_table :users do |t| t.column :first_name, :string, :null => false t.column :last_name, :string, :null => false t.column :account_id, :integer t.column :description, :text t.column :created_at, :datetime t.column :updated_at, :datetimeend
create_table :users do |t| t.column :first_name, :string, :null => false t.column :last_name, :string, :null => false t.column :account_id, :integer t.column :description, :text t.column :created_at, :datetime t.column :updated_at, :datetimeend
create_table :users do |t| t.integer :account_id t.string :first_name, :last_name, :null => false t.text :description t.timestampsend
create_table :users do |t| t.integer :account_id t.string :first_name, :last_name, :null => false t.text :description t.timestampsend
script/generate migration AddMoreToProjects image_url:string complete:boolean script/generate migration AddMoreToProjects image_url:string complete:boolean
class AddMoreToProject < ActiveRecord::Migration
def self.up
add_column :projects, :image_url, :string add_column :projects, :complete, :boolean
end
def self.down
remove_column :projects, :complete
remove_column :projects, :image_url
end
end
class AddMoreToProject < ActiveRecord::Migration
def self.up
add_column :projects, :image_url, :string add_column :projects, :complete, :boolean
end
def self.down
remove_column :projects, :complete
remove_column :projects, :image_url
end
end
script/generate scaffold Project name:string url:string description:text
script/generate scaffold Project name:string url:string description:text
class CreateProjects < ActiveRecord::Migration
def self.up
create_table :projects do |t|
t.string :names, :url
t.text :description
t.timestamps
end
def self.down
drop_table :projects
end
end
class CreateProjects < ActiveRecord::Migration
def self.up
create_table :projects do |t|
t.string :names, :url
t.text :description
t.timestamps
end
def self.down
drop_table :projects
end
end
Where we used to have:
t.integer :commentary_id, :null => false
t.string :commentary_type, :null => false
Where we used to have:
t.integer :commentary_id, :null => false
t.string :commentary_type, :null => false
class VideoCast < ActiveRecord::Base
belongs_to :commentary, :polymorphic => true
end
class VideoCast < ActiveRecord::Base
belongs_to :commentary, :polymorphic => true
end
class CreateVideoCasts < ActiveRecord::Migrationdef self.up
create_table :video_casts do |t|t.references :commentary, :null => false,
:polymorphic => truet.timestamps
endend def self.down
drop_table :video_castsend
end
class CreateVideoCasts < ActiveRecord::Migrationdef self.up
create_table :video_casts do |t|t.references :commentary, :null => false,
:polymorphic => truet.timestamps
endend def self.down
drop_table :video_castsend
end
rake db:create creates database for development environment
rake db:create:all creates database for all environments
rake db:migrate:redo undo your last migration and re-run it
rake db:migrate:reset drops the database, re-creates it, and then runs all migrations
Rake db:rollback goes back one migration level
rake db:create creates database for development environment
rake db:create:all creates database for all environments
rake db:migrate:redo undo your last migration and re-run it
rake db:migrate:reset drops the database, re-creates it, and then runs all migrations
Rake db:rollback goes back one migration level
RailsJitsuhttp://www.railsjitsu.com/use-of-migration-references-in-rails-2-0-and-a-bug
Codefront.nethttp://blog.codefront.net/2007/12/24/generating-migrations-gets-easier-rails-20-a-feature-a-day-6/