Created
December 18, 2018 16:56
-
-
Save matthewrudy/f7510c924c7e1c0a91515d6c4929eef7 to your computer and use it in GitHub Desktop.
An example of adding a column as nullable, setting the default, then making it not null.
This file contains 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 characters
class AddTimestampsToRegions < ActiveRecord::Migration[4.2] | |
def up | |
add_timestamps :regions, null: true | |
execute "UPDATE regions SET created_at = NOW(), updated_at = NOW()" | |
change_column_null :regions, :created_at, false | |
change_column_null :regions, :updated_at, false | |
end | |
def down | |
remove_column :regions, :created_at | |
remove_column :regions, :updated_at | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment