Sha256: ea13a92854ed5d82fc0f8effb9f2f48720a25e390ad4c3cea0282ea8396e93b6

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

class ActsAsTaggableOnMigration < ActiveRecord::Migration
  def self.up
    # We already have a Tag model with a name
    # create_table :tags do |t|
    #   t.string :name
    # end

    # We already have a Taggings model with tag_id, taggable_id and taggable_type
    # so we'll just add the tagger, context, and created_at columns.
    add_column :taggings, :tagger_id, :integer
    add_column :taggings, :tagger_type, :string
    add_column :taggings, :context, :string
    add_column :taggings, :created_at, :datetime

    # We need to set the context on all existing tags to "tags" for them to be recognized
    execute "UPDATE taggings SET context='tags' WHERE context IS NULL"

    # create_table :taggings do |t|
    #   t.references :tag

    #   # You should make sure that the column created is
    #   # long enough to store the required class names.
    #   t.references :taggable, :polymorphic => true
    #   t.references :tagger, :polymorphic => true

    #   t.string :context

    #   t.datetime :created_at
    # end

    remove_index :taggings, :column => ["tag_id", "taggable_id", "taggable_type"]
    add_index :taggings, :tag_id
    add_index :taggings, [:taggable_id, :taggable_type, :context]
  end

  def self.down
    remove_index :taggings, :tag_id
    remove_index :taggings, :column => [:taggable_id, :taggable_type, :context]

    remove_column :taggings, :tagger_id
    remove_column :taggings, :tagger_type
    remove_column :taggings, :context
    remove_column :taggings, :created_at

    add_index "taggings", ["tag_id", "taggable_id", "taggable_type"], :name => "index_taggings_on_tag_id_and_taggable_id_and_taggable_type", :unique => true

    # drop_table :taggings
    # drop_table :tags
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
calagator-1.0.0 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.9 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.8 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.7 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.6 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.5 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.3 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.2 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
grokus-1.0.0.1 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
calagator-1.0.0.rc3 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
calagator-1.0.0.rc2 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
calagator-1.0.0.rc1 db/migrate/20110717231316_acts_as_taggable_on_migration.rb
calagator-0.0.1.pre1 db/migrate/20110717231316_acts_as_taggable_on_migration.rb