Last active
October 6, 2016 00:07
-
-
Save jameskerr/6214777879bd4e60775d93280d4b9f76 to your computer and use it in GitHub Desktop.
Revisions
-
jameskerr revised this gist
Oct 6, 2016 . 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 @@ -58,7 +58,7 @@ For this example, the change would look like this: <screenshot> **Note:** If there are other changes, please do not commit them. They are there because your local database and the production database are out of sync. -
jameskerr revised this gist
Oct 6, 2016 . 1 changed file with 20 additions and 6 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 @@ -6,7 +6,7 @@ Procedures for adding migrations to our Rails application. There is a rails tool to help you make the file. For example, if I wanted to add an age column to the users table, I would run: ```bash > rails g migration add_age_to_users age:integer invoke active_record create db/migrate/20161005225132_add_age_to_users.rb ``` @@ -24,30 +24,44 @@ end **2. Migrate your local database** ```bash > rake db:migrate == 20161005225132 AddAgeToUsers: migrating ==================================== -- add_column(:users, :age, :integer) -> 0.0017s == 20161005225132 AddAgeToUsers: migrated (0.0018s) =========================== ``` Ensure that this succeeds as expected. **3. Test rolling back** ```bash > rake db:rollback == 20161005225132 AddAgeToUsers: reverting ==================================== -- remove_column(:users, :age, :integer) -> 0.0016s == 20161005225132 AddAgeToUsers: reverted (0.0018s) =========================== ``` Ensure that this is a succeeds as expected. Most migrations are automatically reversable. Others can be made automatically reversable by adding additional options. **4. Re-migrate the database** `> rake db:migrate` again **5. Commit your changes** When you run `rake db:migrate` it will change the `db/schema.rb` file. Ensure that the only change to that file is the version number at the top, and the change you made in the migration file. For this example, the change would look like this: <screenshot> Note: If there are other changes, please do not commit them. They are there because your local database and the production database are out of sync. Please use the `bin/restore-snapshot` tool to download and restore a local copy of the database. Then re-migrate your changes. DONE THANKS! -
jameskerr revised this gist
Oct 5, 2016 . 1 changed file with 8 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 @@ -13,7 +13,14 @@ There is a rails tool to help you make the file. For example, if I wanted to add Open the created file and add your migration code. ```ruby # db/migrate/20161005225132_add_age_to_users.rb class AddAgeToUsers < ActiveRecord::Migration def change add_column :users, :age, :integer, default: 0, null: false end end ``` **2. Migrate your local database** -
jameskerr revised this gist
Oct 5, 2016 . 1 changed file with 5 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 @@ -5,7 +5,11 @@ Procedures for adding migrations to our Rails application. There is a rails tool to help you make the file. For example, if I wanted to add an age column to the users table, I would run: ```bash Ξ rails g migration add_age_to_users age:integer invoke active_record create db/migrate/20161005225132_add_age_to_users.rb ``` Open the created file and add your migration code. -
jameskerr revised this gist
Oct 5, 2016 . 1 changed file with 6 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 @@ -1,6 +1,7 @@ Procedures for adding migrations to our Rails application. --- **1. Add your migration file** There is a rails tool to help you make the file. For example, if I wanted to add an age column to the users table, I would run: @@ -10,23 +11,23 @@ Open the created file and add your migration code. <screenshot> **2. Migrate your local database** `rake db:migrate` Ensure that this succeeds as expected. **3. Test rolling back** `rake db:rollback` Ensure that this is a succeeds as expected. Most migrations are automatically reversable. Others can be made automatically reversable by adding additional options. **4. Re-migrate the database** `rake db:migrate` again **5. Commit your changes** When you run `rake db:migrate` it will change the `db/schema.rb` file. Ensure that the only change to that file is the version number at the top, and the change you made in the migration file. -
jameskerr created this gist
Oct 5, 2016 .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,41 @@ Procedures for adding migrations to our Rails application. 1. Add your migration file There is a rails tool to help you make the file. For example, if I wanted to add an age column to the users table, I would run: `rails generate migration add_age_to_users` Open the created file and add your migration code. <screenshot> 2. Migrate your local database `rake db:migrate` Ensure that this succeeds as expected. 3. Tests rolling back `rake db:rollback` Ensure that this is a succeeds as expected. Most migrations are automatically reversable. Others can be made automatically reversable by adding additional options. 4. Re-migrate the database `rake db:migrate` again 5. Commit your changes When you run `rake db:migrate` it will change the `db/schema.rb` file. Ensure that the only change to that file is the version number at the top, and the change you made in the migration file. For this example, the change would look like this: <screenshots> Note: If there are other changes, please do not commit them. They are there because your local database and the production database are out of sync. Please use the `bin/restore-snapshot` tool to download and restore a local copy of the database. Then re-migrate your changes.