Sha256: 10075c43349b000b8681eacd2bfe8be63f1d13eb7c038ed1a46d7bb68be3d18c

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

class AddTimebasedPublishingColumnsToPages < ActiveRecord::Migration
  def up
    add_column :alchemy_pages, :public_on, :datetime
    add_column :alchemy_pages, :public_until, :datetime
    add_index :alchemy_pages, [:public_on, :public_until]

    update <<-SQL.strip_heredoc
      UPDATE alchemy_pages
      SET public_on = published_at
      WHERE published_at IS NOT NULL AND public=#{ActiveRecord::Base.connection.quoted_true}
    SQL

    remove_column :alchemy_pages, :public
  end

  def down
    add_column :alchemy_pages, :public, :boolean, default: false
    current_time = ActiveRecord::Base.connection.quoted_date(Time.current)

    update <<-SQL.strip_heredoc
      UPDATE alchemy_pages
      SET public = (
        public_on IS NOT NULL AND public_on < '#{current_time}'
        AND (public_until > '#{current_time}' OR public_until IS NULL)
      )
    SQL

    remove_index :alchemy_pages, [:public_on, :public_until]
    remove_column :alchemy_pages, :public_on
    remove_column :alchemy_pages, :public_until
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.6 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.5 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.4 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.3 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.2 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.1 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-4.0.0.beta db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.6.0 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.5.0 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.4.2 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.5.0.rc2 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.5.0.rc1 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.4.1 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.4.0 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb
alchemy_cms-3.4.0.rc1 db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb