Sha256: 8bf3c6a87f7eb3851bb860b3f22cabfa479d0f1fe558913638ac724dad514428

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

require 'bare_migration'
class FixupForthcomingPublications < ActiveRecord::Migration
  class Trigger < ActiveRecord::Base
    belongs_to :pending_items, :polymorphic => true
  end

  class Content < ActiveRecord::Base
  end

  class Article < Content
  end

  def self.up
    return if $schema_generator
    Article.transaction do
      Trigger.transaction do
        Article.find(:all, :conditions => ['published = ? AND published_at > ?',
                                           true, Time.now]).each do |art|
          Trigger.create!(:pending_item   => art,
                          :due_at         => art.published_at,
                          :trigger_method => 'publish!')
          art.update_attribute(:published, false)
        end
      end
    end
  end

  def self.down
    return if $schema_generator
    Article.transaction do
      Trigger.transaction do
        Trigger.find(:all,
                     :conditions => "pending_item_type = 'Article' AND trigger_method = 'publish!'").each do |t|
          t.pending_item.update_attribute(:published, :true)
          t.destroy
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
typo-3.99.0 db/migrate/046_fixup_forthcoming_publications.rb
typo-3.99.2 db/migrate/046_fixup_forthcoming_publications.rb
typo-3.99.3 db/migrate/046_fixup_forthcoming_publications.rb
typo-3.99.1 db/migrate/046_fixup_forthcoming_publications.rb
typo-3.99.4 db/migrate/046_fixup_forthcoming_publications.rb
typo-4.0.0 db/migrate/046_fixup_forthcoming_publications.rb