Sha256: 55ce6310d20b39d4e37bdb75185aa618ae1ec9126d8519af5b70b2401540afdd

Contents?: true

Size: 1.09 KB

Versions: 30

Compression:

Stored size: 1.09 KB

Contents

class Bare34Content < ActiveRecord::Base
  include BareMigration
end

class BoolifyPublished < ActiveRecord::Migration
  def self.up
    STDERR.puts "Boolifying contents.published"
    modify_tables_and_update([:rename_column, Bare34Content, :published, :old_pub],
                             [:add_column,    Bare34Content, :published, :boolean, { :default => true }]) do |c|
      unless $schema_generator
        if c.old_pub.nil?
          c.published = true
        else
          c.published = (!c.old_pub.to_i.zero? ? true : false)
        end
      end
    end
    remove_column :contents, :old_pub
  end

  def self.down
    STDERR.puts "Un-Boolifying contents.published"
    modify_tables_and_update([:rename_column, Bare34Content, :published, :old_pub],
                             [:add_column,    Bare34Content, :published, :integer]) do |c|
      unless $schema_generator
        say "Old published: #{c.old_pub}"
        if c.old_pub.nil?
          c.published = 1
        else
          c.published = c.old_pub ? 1 : 0
        end
      end
    end
    remove_column :contents, :old_pub
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
typo-5.5 db/migrate/034_boolify_published.rb
typo-5.4.4 db/migrate/034_boolify_published.rb
typo-5.4.3 db/migrate/034_boolify_published.rb
typo-5.4.2 db/migrate/034_boolify_published.rb
typo-5.4.1 db/migrate/034_boolify_published.rb
typo-5.4 db/migrate/034_boolify_published.rb
typo-3.99.0 db/migrate/034_boolify_published.rb
typo-3.99.2 db/migrate/034_boolify_published.rb
typo-3.99.1 db/migrate/034_boolify_published.rb
typo-3.99.3 db/migrate/034_boolify_published.rb
typo-4.0.0 db/migrate/034_boolify_published.rb
typo-3.99.4 db/migrate/034_boolify_published.rb
typo-4.0.2 db/migrate/034_boolify_published.rb
typo-4.0.1 db/migrate/034_boolify_published.rb
typo-4.0.3 db/migrate/034_boolify_published.rb
typo-4.1.1 db/migrate/034_boolify_published.rb
typo-5.0.1 db/migrate/034_boolify_published.rb
typo-4.1 db/migrate/034_boolify_published.rb
typo-5.0.2 db/migrate/034_boolify_published.rb
typo-5.0.3.98.1 db/migrate/034_boolify_published.rb