Skip to content

Instantly share code, notes, and snippets.

@jameskerr
Last active October 6, 2016 00:07
Show Gist options
  • Select an option

  • Save jameskerr/6214777879bd4e60775d93280d4b9f76 to your computer and use it in GitHub Desktop.

Select an option

Save jameskerr/6214777879bd4e60775d93280d4b9f76 to your computer and use it in GitHub Desktop.

Revisions

  1. jameskerr revised this gist Oct 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion migrations.md
    Original file line number Diff line number Diff line change
    @@ -58,7 +58,7 @@ For this example, the change would look like this:

    <screenshot>

    Note:
    **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.

  2. jameskerr revised this gist Oct 6, 2016. 1 changed file with 20 additions and 6 deletions.
    26 changes: 20 additions & 6 deletions migrations.md
    Original 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
    > 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**

    `rake db:migrate`
    ```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**

    `rake db:rollback`
    ```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
    `> 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>
    <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.
    Please use the `bin/restore-snapshot` tool to download and restore a local copy of the database. Then re-migrate your changes.

    DONE THANKS!
  3. jameskerr revised this gist Oct 5, 2016. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion migrations.md
    Original 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.

    <screenshot>
    ```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**

  4. jameskerr revised this gist Oct 5, 2016. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion migrations.md
    Original 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:

    `rails generate migration add_age_to_users`
    ```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.

  5. jameskerr revised this gist Oct 5, 2016. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions migrations.md
    Original 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
    **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
    **2. Migrate your local database**

    `rake db:migrate`

    Ensure that this succeeds as expected.

    3. Tests rolling back
    **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
    **4. Re-migrate the database**

    `rake db:migrate` again

    5. Commit your changes
    **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.

  6. jameskerr created this gist Oct 5, 2016.
    41 changes: 41 additions & 0 deletions migrations.md
    Original 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.