Method: Redmineup::ActsAsTaggable::Taggable::ClassMethods#create_taggable_table

Defined in:
lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb

#create_taggable_table(options = {}) ⇒ Object

Create the taggable tables

Options hash:

  • :table_name - use a table name other than viewings

To be used during migration, but can also be used in other places



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb', line 49

def create_taggable_table(options = {})
  tag_name_table = options[:tags] || :tags

  if !self.connection.table_exists?(tag_name_table)
    self.connection.create_table(tag_name_table) do |t|
      t.column :name, :string
    end
  end

  taggings_name_table = options[:taggings] || :taggings
  if !self.connection.table_exists?(taggings_name_table)
    self.connection.create_table(taggings_name_table) do |t|
      t.column :tag_id, :integer
      t.column :taggable_id, :integer

      # You should make sure that the column created is
      # long enough to store the required class names.
      t.column :taggable_type, :string

      t.column :created_at, :datetime
    end

    self.connection.add_index :taggings, :tag_id
    self.connection.add_index :taggings, [:taggable_id, :taggable_type]
  end
end