Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class UpdateArticles < ActiveRecord::Migration
class Article < ActiveRecord::Base; end
def self.up
add_column :articles, :published_at, :datetime, :null => true
say_with_time "Updating published_at column" do
Article.reset_column_information
Article.update_all 'published_at=created_at', 'publish IS TRUE'
end
add_index :articles, :published_at
remove_column :articles, :publish
end
def self.down
add_column :articles, :publish, :boolean
say_with_time "Updating publish column" do
Article.reset_column_information
Article.update_all 'publish=true', 'published_at IS NOT NULL'
end
remove_column :articles, :published_at
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.