Created
October 10, 2017 14:15
-
-
Save matbrady/6d8a3ba6bea3129fa1d5b0ab8ced82d1 to your computer and use it in GitHub Desktop.
Add Not Null Column to Existing Model
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 characters
class AddPublishableToTimelinePage < ActiveRecord::Migration[5.0] | |
def up | |
add_column :timeline_pages, :published_at, :datetime | |
add_column :timeline_pages, :status, :string, null: false, default: "draft" | |
add_column :timeline_pages, :uuid, :text | |
TimelinePage.update_all({ | |
published_at: Time.now, | |
uuid: SecureRandom.uuid | |
}) | |
change_column_null :timeline_pages, :published_at, false | |
change_column_null :timeline_pages, :uuid, false | |
end | |
def down | |
remove_column :timeline_pages, :published_at, :datetime | |
remove_column :timeline_pages, :status, :string | |
remove_column :timeline_pages, :uuid, :text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment