Permalink
Browse files

Namespacing tables to have gutentag_ prefix.

This could have been a migration, but then people installing Gutentag for the first time who already have tables named 'tags' or 'taggings' would have migrations complain. So, renaming everything in existing migrations instead (for people starting now with Gutentag), and there'll be a note in the README for anyone upgrading.
  • Loading branch information...
1 parent e0d2d31 commit 1093397c4c69710dfe1ae0493e7b2eaa6f3b5d54 @pat committed Sep 10, 2013
@@ -1,10 +1,12 @@
class Gutentag::Tag < ActiveRecord::Base
+ self.table_name = 'gutentag_tags'
+
has_many :taggings, :class_name => 'Gutentag::Tagging',
:dependent => :destroy
attr_accessible :name if Rails.version.to_s < '4.0.0'
- scope :by_weight, ->{ order('tags.taggings_count DESC') }
+ scope :by_weight, ->{ order('gutentag_tags.taggings_count DESC') }
validates :name, :presence => true, :uniqueness => {:case_sensitive => false}
@@ -1,4 +1,6 @@
class Gutentag::Tagging < ActiveRecord::Base
+ self.table_name = 'gutentag_taggings'
+
belongs_to :taggable, :polymorphic => true
belongs_to :tag, :class_name => 'Gutentag::Tag', :counter_cache => true
@@ -1,27 +1,27 @@
class GutentagTables < ActiveRecord::Migration
def up
- create_table :taggings do |t|
+ create_table :gutentag_taggings do |t|
t.integer :tag_id, :null => false
t.integer :taggable_id, :null => false
t.string :taggable_type, :null => false
t.timestamps
end
- add_index :taggings, :tag_id
- add_index :taggings, [:taggable_type, :taggable_id]
- add_index :taggings, [:taggable_type, :taggable_id, :tag_id],
+ add_index :gutentag_taggings, :tag_id
+ add_index :gutentag_taggings, [:taggable_type, :taggable_id]
+ add_index :gutentag_taggings, [:taggable_type, :taggable_id, :tag_id],
:unique => true, :name => 'unique_taggings'
- create_table :tags do |t|
+ create_table :gutentag_tags do |t|
t.string :name, :null => false
t.timestamps
end
- add_index :tags, :name, :unique => true
+ add_index :gutentag_tags, :name, :unique => true
end
def down
- drop_table :tags
- drop_table :taggings
+ drop_table :gutentag_tags
+ drop_table :gutentag_taggings
end
end
@@ -1,7 +1,7 @@
class GutentagCacheCounter < ActiveRecord::Migration
def up
- add_column :tags, :taggings_count, :integer, :default => 0
- add_index :tags, :taggings_count
+ add_column :gutentag_tags, :taggings_count, :integer, :default => 0
+ add_index :gutentag_tags, :taggings_count
Gutentag::Tag.reset_column_information
Gutentag::Tag.pluck(:id).each do |tag_id|
@@ -10,6 +10,6 @@ def up
end
def down
- remove_column :tags, :taggings_count
+ remove_column :gutentag_tags, :taggings_count
end
end
@@ -1,11 +1,11 @@
class NoNullCounters < ActiveRecord::Migration
def up
- change_column :tags, :taggings_count, :integer, :default => 0,
+ change_column :gutentag_tags, :taggings_count, :integer, :default => 0,
:null => false
end
def down
- change_column :tags, :taggings_count, :integer, :default => 0,
+ change_column :gutentag_tags, :taggings_count, :integer, :default => 0,
:null => true
end
end

0 comments on commit 1093397

Please sign in to comment.