From c0ed5a68c3cf68fb121f9a59ee752b314c047970 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Thu, 11 Jul 2024 20:18:55 +0200 Subject: [PATCH] Install acts_as_taggable gem --- Gemfile | 3 +- Gemfile.lock | 3 ++ ...on_migration.acts_as_taggable_on_engine.rb | 34 +++++++++++++++++++ ...ique_indices.acts_as_taggable_on_engine.rb | 24 +++++++++++++ ...ache_to_tags.acts_as_taggable_on_engine.rb | 17 ++++++++++ ...ggable_index.acts_as_taggable_on_engine.rb | 13 +++++++ ...or_tag_names.acts_as_taggable_on_engine.rb | 13 +++++++ ..._on_taggings.acts_as_taggable_on_engine.rb | 25 ++++++++++++++ ..._to_taggings.acts_as_taggable_on_engine.rb | 14 ++++++++ db/schema.rb | 34 ++++++++++++++++++- 10 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240711181626_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181627_add_missing_unique_indices.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181628_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181629_add_missing_taggable_index.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181630_change_collation_for_tag_names.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181631_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb create mode 100644 db/migrate/20240711181632_add_tenant_to_taggings.acts_as_taggable_on_engine.rb diff --git a/Gemfile b/Gemfile index 9969c65..7b27dc7 100644 --- a/Gemfile +++ b/Gemfile @@ -62,4 +62,5 @@ group :development do # gem "spring" end -gem "money" \ No newline at end of file +gem "money" +gem 'acts-as-taggable-on' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 0a4cb1f..c1556c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,8 @@ GEM minitest (>= 5.1) mutex_m tzinfo (~> 2.0) + acts-as-taggable-on (10.0.0) + activerecord (>= 6.1, < 7.2) base64 (0.2.0) bigdecimal (3.1.8) bindex (0.8.1) @@ -252,6 +254,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + acts-as-taggable-on bootsnap debug faker diff --git a/db/migrate/20240711181626_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20240711181626_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..4690763 --- /dev/null +++ b/db/migrate/20240711181626_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/20240711181627_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20240711181627_add_missing_unique_indices.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..ebd46fd --- /dev/null +++ b/db/migrate/20240711181627_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/20240711181628_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20240711181628_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..d17afe8 --- /dev/null +++ b/db/migrate/20240711181628_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/20240711181629_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20240711181629_add_missing_taggable_index.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..52f696b --- /dev/null +++ b/db/migrate/20240711181629_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/20240711181630_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20240711181630_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..47fd928 --- /dev/null +++ b/db/migrate/20240711181630_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/20240711181631_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20240711181631_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..f5aaaf9 --- /dev/null +++ b/db/migrate/20240711181631_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/migrate/20240711181632_add_tenant_to_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20240711181632_add_tenant_to_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 0000000..b62b660 --- /dev/null +++ b/db/migrate/20240711181632_add_tenant_to_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 7) +class AddTenantToTaggings < ActiveRecord::Migration[6.0] + def self.up + add_column ActsAsTaggableOn.taggings_table, :tenant, :string, limit: 128 + add_index ActsAsTaggableOn.taggings_table, :tenant unless index_exists? ActsAsTaggableOn.taggings_table, :tenant + end + + def self.down + remove_index ActsAsTaggableOn.taggings_table, :tenant + remove_column ActsAsTaggableOn.taggings_table, :tenant + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e13f74..0ec1413 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_11_180753) do +ActiveRecord::Schema[7.1].define(version: 2024_07_11_181632) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -35,4 +35,36 @@ ActiveRecord::Schema[7.1].define(version: 2024_07_11_180753) do t.datetime "updated_at", null: false 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.string "tenant", limit: 128 + 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" + t.index ["tenant"], name: "index_taggings_on_tenant" + 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 + + add_foreign_key "taggings", "tags" end