Install acts_as_taggable gem
This commit is contained in:
parent
a0119ad0cc
commit
c0ed5a68c3
3
Gemfile
3
Gemfile
@ -62,4 +62,5 @@ group :development do
|
||||
# gem "spring"
|
||||
end
|
||||
|
||||
gem "money"
|
||||
gem "money"
|
||||
gem 'acts-as-taggable-on'
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
34
db/schema.rb
generated
34
db/schema.rb
generated
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user