Sha256: 08931ab344307f27216817cb6b1c9d79362fdaa4799039a6e971ca4c5d500036

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

class AddCategorizationModel < ActiveRecord::Migration
  class ArticlesCategory < ActiveRecord::Base
    include BareMigration
  end

  class Categorization < ActiveRecord::Base
    include BareMigration
  end

  def self.up
    create_table :categorizations do |t|
      t.column :article_id, :integer
      t.column :category_id, :integer
      t.column :is_primary, :boolean
    end

    unless $schema_generator
      ArticlesCategory.find(:all).each do |ac|
        Categorization.create!(:article_id => ac.article_id,
                               :category_id => ac.category_id,
                               :is_primary => (ac.is_primary == 1))
      end rescue nil
    end

    drop_table :articles_categories rescue nil
  end

  def self.down
    create_table :articles_categories, :id => false do |t|
      t.column :article_id, :integer
      t.column :category_id, :integer
      t.column :is_primary, :integer
    end

    unless $schema_generator
      Categorization.find(:all).each do |c|
        ArticlesCategory.create!(:article_id => c.article_id,
                                 :category_id => c.category_id,
                                 :is_primary => c.is_primary ? 1 : 0)
      end
    end

    drop_table :categorizations
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
typo-5.0.1 db/migrate/057_add_categorization_model.rb
typo-5.0.2 db/migrate/057_add_categorization_model.rb
typo-5.0.3.98.1 db/migrate/057_add_categorization_model.rb
typo-5.0 db/migrate/057_add_categorization_model.rb
typo-5.0.3.98 db/migrate/057_add_categorization_model.rb
typo-5.1.1 db/migrate/057_add_categorization_model.rb
typo-5.1.2 db/migrate/057_add_categorization_model.rb
typo-5.1.3 db/migrate/057_add_categorization_model.rb
typo-5.1 db/migrate/057_add_categorization_model.rb