Forked from amejiarosario/rails_migration_cheatsheet.md
Last active
August 29, 2015 14:23
-
-
Save hophacker/3ad016db693dd03bf879 to your computer and use it in GitHub Desktop.
Revisions
-
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -63,16 +63,19 @@ $ rake db:reset #drop database and recreate it $ rake db:migrate:up VERSION=20080906120000 ``` ## Migrations commands ``` rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:test:prepare # Rebuild it from scratch according to the specs defined in the development database ``` ## more Database commands (rake -T db) ``` rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t... rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -63,7 +63,9 @@ $ rake db:reset #drop database and recreate it $ rake db:migrate:up VERSION=20080906120000 ``` ## Migrations commands (rake -T db) ## Database commands (rake -T db) ``` rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t... rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,3 +62,19 @@ $ rake db:migrate:redo STEP=3 $ rake db:reset #drop database and recreate it $ rake db:migrate:up VERSION=20080906120000 ``` ## Rake -T db ``` rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in t... rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load fixtures into the current environment's database. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) rake db:structure:dump # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql rake db:version # Retrieves the current schema version number ``` -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 20 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,8 +32,9 @@ YYYYMMDDHHMMSS_create_products.rb especial type: * :references ## create_table ### Commands to create migrations ``` $ rails generate model Product name:string description:text @@ -42,5 +43,22 @@ $ rails generate migration RemovePartNumberFromProducts part_number:string $ rails generate migration AddDetailsToProducts part_number:string price:decimal ``` ## change_table * add_column * add_index * add_timestamps * create_table * remove_timestamps * rename_column * rename_index * rename_table ## Running Migrations ``` $ rake db:migrate VERSION=20080906120000 $ rake db:rollback $ rake db:rollback STEP=3 $ rake db:migrate:redo STEP=3 $ rake db:reset #drop database and recreate it $ rake db:migrate:up VERSION=20080906120000 ``` -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 33 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Rails Migration http://guides.rubyonrails.org/migrations.html ## Migrations methods: * add_column * add_index * change_column @@ -12,4 +12,35 @@ http://guides.rubyonrails.org/migrations.html * remove_index * rename_column Basic format YYYYMMDDHHMMSS_create_products.rb ## Supported types * :binary * :boolean * :date * :datetime * :decimal * :float * :integer * :primary_key * :string * :text * :time * :timestamp especial type: * :references ## Commands to create migrations ``` $ rails generate model Product name:string description:text $ rails generate migration AddPartNumberToProducts part_number:string $ rails generate migration RemovePartNumberFromProducts part_number:string $ rails generate migration AddDetailsToProducts part_number:string price:decimal ``` -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,15 @@ === Rails Migration http://guides.rubyonrails.org/migrations.html == Migrations methods: * add_column * add_index * change_column * change_table * create_table * drop_table * remove_column * remove_index * rename_column -
amejiarosario renamed this gist
Jun 18, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,3 @@ Rails Migration "http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html" -
amejiarosario revised this gist
Jun 18, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ hn. Rails Migration !"http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html" -
amejiarosario created this gist
Jun 18, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ == Rails Migration !"http://guides.rubyonrails.org/migrations.html":"http://guides.rubyonrails.org/migrations.html"