diff --git a/db/migrate/20250204102932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20250204102932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..4690763 --- /dev/null +++ b/db/migrate/20250204102932_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 1) +class ActsAsTaggableOnMigration < ActiveRecord::Migration[6.0] + def self.up + create_table ActsAsTaggableOn.tags_table do |t| + t.string :name + t.timestamps + end + + create_table ActsAsTaggableOn.taggings_table do |t| + t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table } + + # 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 + + # Limit is created to prevent MySQL error on index + # length for MyISAM table type: http://bit.ly/vgW2Ql + t.string :context, limit: 128 + + t.datetime :created_at + end + + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type context], + name: 'taggings_taggable_context_idx' + end + + def self.down + drop_table ActsAsTaggableOn.taggings_table + drop_table ActsAsTaggableOn.tags_table + end +end diff --git a/db/migrate/20250204102933_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20250204102933_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..ebd46fd --- /dev/null +++ b/db/migrate/20250204102933_add_missing_unique_indices.acts_as_taggable_on_engine.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 2) +class AddMissingUniqueIndices < ActiveRecord::Migration[6.0] + def self.up + add_index ActsAsTaggableOn.tags_table, :name, unique: true + + remove_index ActsAsTaggableOn.taggings_table, :tag_id if index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' + add_index ActsAsTaggableOn.taggings_table, + %i[tag_id taggable_id taggable_type context tagger_id tagger_type], + unique: true, name: 'taggings_idx' + end + + def self.down + remove_index ActsAsTaggableOn.tags_table, :name + + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_idx' + + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists?(ActsAsTaggableOn.taggings_table, :tag_id) + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type context], + name: 'taggings_taggable_context_idx' + end +end diff --git a/db/migrate/20250204102934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20250204102934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..d17afe8 --- /dev/null +++ b/db/migrate/20250204102934_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 3) +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[6.0] + def self.up + add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0 + + ActsAsTaggableOn::Tag.reset_column_information + ActsAsTaggableOn::Tag.find_each do |tag| + ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table) + end + end + + def self.down + remove_column ActsAsTaggableOn.tags_table, :taggings_count + end +end diff --git a/db/migrate/20250204102935_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20250204102935_add_missing_taggable_index.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..52f696b --- /dev/null +++ b/db/migrate/20250204102935_add_missing_taggable_index.acts_as_taggable_on_engine.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 4) +class AddMissingTaggableIndex < ActiveRecord::Migration[6.0] + def self.up + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type context], + name: 'taggings_taggable_context_idx' + end + + def self.down + remove_index ActsAsTaggableOn.taggings_table, name: 'taggings_taggable_context_idx' + end +end diff --git a/db/migrate/20250204102936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20250204102936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..47fd928 --- /dev/null +++ b/db/migrate/20250204102936_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 5) +# This migration is added to circumvent issue #623 and have special characters +# work properly + +class ChangeCollationForTagNames < ActiveRecord::Migration[6.0] + def up + if ActsAsTaggableOn::Utils.using_mysql? + execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") + end + end +end diff --git a/db/migrate/20250204102937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20250204102937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..f5aaaf9 --- /dev/null +++ b/db/migrate/20250204102937_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 6) +class AddMissingIndexesOnTaggings < ActiveRecord::Migration[6.0] + def change + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id + add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, + :taggable_id + add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, + :taggable_type + add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, + :tagger_id + add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context + + unless index_exists? ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] + add_index ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] + end + + unless index_exists? ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], + name: 'taggings_idy' + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], + name: 'taggings_idy' + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 64ef9ac..b8106bb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -90,6 +90,35 @@ t.index ["user_id"], name: "index_sessions_on_user_id" end + create_table "taggings", force: :cascade do |t| + t.bigint "tag_id" + t.string "taggable_type" + t.bigint "taggable_id" + t.string "tagger_type" + t.bigint "tagger_id" + t.string "context", limit: 128 + t.datetime "created_at", precision: nil + t.index ["context"], name: "index_taggings_on_context" + t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true + t.index ["tag_id"], name: "index_taggings_on_tag_id" + t.index ["taggable_id", "taggable_type", "context"], name: "taggings_taggable_context_idx" + t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" + t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id" + t.index ["taggable_type"], name: "index_taggings_on_taggable_type" + t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type" + t.index ["tagger_id"], name: "index_taggings_on_tagger_id" + t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id" + end + + create_table "tags", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "taggings_count", default: 0 + t.index ["name"], name: "index_tags_on_name", unique: true + end + create_table "topics", force: :cascade do |t| t.bigint "provider_id" t.bigint "language_id" @@ -126,4 +155,5 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "sessions", "users" + add_foreign_key "taggings", "tags" end