Skip to content

Instantly share code, notes, and snippets.

@matbrady
Created October 10, 2017 14:15
Show Gist options
  • Save matbrady/6d8a3ba6bea3129fa1d5b0ab8ced82d1 to your computer and use it in GitHub Desktop.
Save matbrady/6d8a3ba6bea3129fa1d5b0ab8ced82d1 to your computer and use it in GitHub Desktop.
Add Not Null Column to Existing Model
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