Feature #1448 » 0003-merge-migrations.patch
db/migrate/20180802191932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 1) |
|
2 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
3 |
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2]; end |
|
4 |
else |
|
5 |
class ActsAsTaggableOnMigration < ActiveRecord::Migration; end |
|
6 |
end |
|
7 |
ActsAsTaggableOnMigration.class_eval do |
|
1 |
class ActsAsTaggableOnMigration < ActiveRecord::Migration[4.2] |
|
8 | 2 |
def self.up |
9 |
create_table :tags do |t| |
|
10 |
t.string :name |
|
3 |
unless table_exists?(:tags) |
|
4 |
create_table :tags do |t| |
|
5 |
t.string :name |
|
6 |
end |
|
11 | 7 |
end |
12 | 8 | |
13 |
create_table :taggings do |t| |
|
14 |
t.references :tag |
|
9 |
unless table_exists?(:taggings) |
|
10 |
create_table :taggings do |t| |
|
11 |
t.references :tag |
|
15 | 12 | |
16 |
# You should make sure that the column created is |
|
17 |
# long enough to store the required class names. |
|
18 |
t.references :taggable, polymorphic: true |
|
19 |
t.references :tagger, polymorphic: true |
|
13 |
# You should make sure that the column created is
|
|
14 |
# long enough to store the required class names.
|
|
15 |
t.references :taggable, polymorphic: true
|
|
16 |
t.references :tagger, polymorphic: true
|
|
20 | 17 | |
21 |
# Limit is created to prevent MySQL error on index |
|
22 |
# length for MyISAM table type: http://bit.ly/vgW2Ql |
|
23 |
t.string :context, limit: 128 |
|
18 |
# Limit is created to prevent MySQL error on index
|
|
19 |
# length for MyISAM table type: http://bit.ly/vgW2Ql
|
|
20 |
t.string :context, limit: 128
|
|
24 | 21 | |
25 |
t.datetime :created_at |
|
22 |
t.datetime :created_at |
|
23 |
end |
|
26 | 24 |
end |
27 | 25 | |
28 |
add_index :taggings, :tag_id
|
|
26 |
add_index :tags, :name, unique: true unless index_exists?(:tags, :name)
|
|
29 | 27 |
add_index :taggings, [:taggable_id, :taggable_type, :context] |
28 |
add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id |
|
29 |
add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id |
|
30 |
add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type |
|
31 |
add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id |
|
32 |
add_index :taggings, :context unless index_exists? :taggings, :context |
|
33 | ||
34 |
unless index_exists? :taggings, [:tagger_id, :tagger_type] |
|
35 |
add_index :taggings, [:tagger_id, :tagger_type] |
|
36 |
end |
|
37 | ||
38 |
unless index_exists? :taggings, [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], unique: true, name: 'taggings_idx' |
|
39 |
add_index :taggings, |
|
40 |
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], |
|
41 |
unique: true, name: 'taggings_idx' |
|
42 |
end |
|
43 | ||
44 |
unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' |
|
45 |
add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' |
|
46 |
end |
|
30 | 47 |
end |
31 | 48 | |
32 | 49 |
def self.down |
db/migrate/20180802191933_add_missing_unique_indices.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 2) |
|
2 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
3 |
class AddMissingUniqueIndices < ActiveRecord::Migration[4.2]; end |
|
4 |
else |
|
5 |
class AddMissingUniqueIndices < ActiveRecord::Migration; end |
|
6 |
end |
|
7 |
AddMissingUniqueIndices.class_eval do |
|
8 |
def self.up |
|
9 |
add_index :tags, :name, unique: true |
|
10 | ||
11 |
remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id) |
|
12 |
remove_index :taggings, [:taggable_id, :taggable_type, :context] |
|
13 |
add_index :taggings, |
|
14 |
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], |
|
15 |
unique: true, name: 'taggings_idx' |
|
16 |
end |
|
17 | ||
18 |
def self.down |
|
19 |
remove_index :tags, :name |
|
20 | ||
21 |
remove_index :taggings, name: 'taggings_idx' |
|
22 | ||
23 |
add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id) |
|
24 |
add_index :taggings, [:taggable_id, :taggable_type, :context] |
|
25 |
end |
|
26 |
end |
db/migrate/20180802191934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 3) |
|
2 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
3 |
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2]; end |
|
4 |
else |
|
5 |
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration; end |
|
6 |
end |
|
7 |
AddTaggingsCounterCacheToTags.class_eval do |
|
1 |
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[4.2] |
|
8 | 2 |
def self.up |
9 |
add_column :tags, :taggings_count, :integer, default: 0 |
|
3 |
unless column_exists?(:tags, :taggings_count, :integer) |
|
4 |
add_column :tags, :taggings_count, :integer, default: 0 |
|
5 |
end |
|
10 | 6 | |
11 | 7 |
ActsAsTaggableOn::Tag.reset_column_information |
12 | 8 |
ActsAsTaggableOn::Tag.find_each do |tag| |
db/migrate/20180802191935_add_missing_taggable_index.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 4) |
|
2 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
3 |
class AddMissingTaggableIndex < ActiveRecord::Migration[4.2]; end |
|
4 |
else |
|
5 |
class AddMissingTaggableIndex < ActiveRecord::Migration; end |
|
6 |
end |
|
7 |
AddMissingTaggableIndex.class_eval do |
|
8 |
def self.up |
|
9 |
add_index :taggings, [:taggable_id, :taggable_type, :context] |
|
10 |
end |
|
11 | ||
12 |
def self.down |
|
13 |
remove_index :taggings, [:taggable_id, :taggable_type, :context] |
|
14 |
end |
|
15 |
end |
db/migrate/20180802191936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 5) |
|
2 |
# This migration is added to circumvent issue #623 and have special characters |
|
3 |
# work properly |
|
4 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
5 |
class ChangeCollationForTagNames < ActiveRecord::Migration[4.2]; end |
|
6 |
else |
|
7 |
class ChangeCollationForTagNames < ActiveRecord::Migration; end |
|
8 |
end |
|
9 |
ChangeCollationForTagNames.class_eval do |
|
1 |
class ChangeCollationForTagNames < ActiveRecord::Migration[4.2] |
|
10 | 2 |
def up |
11 | 3 |
if ActsAsTaggableOn::Utils.using_mysql? |
12 | 4 |
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") |
db/migrate/20180802191937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb | ||
---|---|---|
1 |
# This migration comes from acts_as_taggable_on_engine (originally 6) |
|
2 |
if ActiveRecord.gem_version >= Gem::Version.new('5.0') |
|
3 |
class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end |
|
4 |
else |
|
5 |
class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end |
|
6 |
end |
|
7 |
AddMissingIndexesOnTaggings.class_eval do |
|
8 |
def change |
|
9 |
add_index :taggings, :tag_id unless index_exists? :taggings, :tag_id |
|
10 |
add_index :taggings, :taggable_id unless index_exists? :taggings, :taggable_id |
|
11 |
add_index :taggings, :taggable_type unless index_exists? :taggings, :taggable_type |
|
12 |
add_index :taggings, :tagger_id unless index_exists? :taggings, :tagger_id |
|
13 |
add_index :taggings, :context unless index_exists? :taggings, :context |
|
14 | ||
15 |
unless index_exists? :taggings, [:tagger_id, :tagger_type] |
|
16 |
add_index :taggings, [:tagger_id, :tagger_type] |
|
17 |
end |
|
18 | ||
19 |
unless index_exists? :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' |
|
20 |
add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' |
|
21 |
end |
|
22 |
end |
|
23 |
end |