Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix setup for tags (#12517)

Łukasz Adamczyk58828c4f2fe2
diff --git a/admin/app/helpers/spree/admin/tags_helper.rb b/admin/app/helpers/spree/admin/tags_helper.rb
index 9909156c47..3cd53157de 100644
--- a/admin/app/helpers/spree/admin/tags_helper.rb
+++ b/admin/app/helpers/spree/admin/tags_helper.rb
@@ -12,7 +12,7 @@ module Spree
def post_tags_scope
@post_tags_scope ||= ActsAsTaggableOn::Tag.
joins(:taggings).
- where('taggings.taggable_type = ?', 'Spree::Post').
+ where("#{ActsAsTaggableOn.taggings_table}.taggable_type = ?", 'Spree::Post').
for_context(:tags)
end
@@ -23,7 +23,7 @@ module Spree
def user_tags_scope
@user_tags_scope ||= ActsAsTaggableOn::Tag.
joins(:taggings).
- where('taggings.taggable_type = ?', Spree.user_class.to_s).
+ where("#{ActsAsTaggableOn.taggings_table}.taggable_type = ?", Spree.user_class.to_s).
for_context(:tags)
end
diff --git a/core/config/initializers/acts_as_taggable_on.rb b/core/config/initializers/acts_as_taggable_on.rb
new file mode 100644
index 0000000000..63b7d4836e
--- /dev/null
+++ b/core/config/initializers/acts_as_taggable_on.rb
@@ -0,0 +1,2 @@
+ActsAsTaggableOn.tags_table = 'spree_tags'
+ActsAsTaggableOn.taggings_table = 'spree_taggings'
diff --git a/core/db/migrate/20250314144210_create_spree_taggings_and_spree_tags.rb b/core/db/migrate/20250314144210_create_spree_taggings_and_spree_tags.rb
new file mode 100644
index 0000000000..aee40ed6fb
--- /dev/null
+++ b/core/db/migrate/20250314144210_create_spree_taggings_and_spree_tags.rb
@@ -0,0 +1,38 @@
+class CreateSpreeTaggingsAndSpreeTags < ActiveRecord::Migration[7.2]
+ def change
+ create_table :spree_taggings 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 :spree_tags 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
+
+ if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
+ add_index :spree_tags, 'lower(name) varchar_pattern_ops', name: 'index_spree_tags_on_lower_name'
+ end
+ end
+end
diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rb
index 0ee0c750f2..6548ed31a8 100644
--- a/core/lib/generators/spree/install/install_generator.rb
+++ b/core/lib/generators/spree/install/install_generator.rb
@@ -123,8 +123,11 @@ module Spree
def install_migrations
say_status :copying, 'migrations'
silence_stream(STDOUT) do
- silence_warnings { rake 'railties:install:migrations' }
- silence_warnings { rake 'acts_as_taggable_on_engine:install:migrations' }
+ silence_warnings { rake 'active_storage:install:migrations' }
+ silence_warnings { rake 'action_mailbox:install:migrations' }
+ silence_warnings { rake 'action_text:install:migrations' }
+ silence_warnings { rake 'spree:install:migrations' }
+ silence_warnings { rake 'spree_api:install:migrations' }
end
end
diff --git a/core/lib/spree/migrations.rb b/core/lib/spree/migrations.rb
index ed550cf7d7..2a1a67cd59 100644
--- a/core/lib/spree/migrations.rb
+++ b/core/lib/spree/migrations.rb
@@ -36,7 +36,7 @@ module Spree
missing_migrations.each do |migration|
puts "[#{engine_name.capitalize} WARNING] #{migration} from #{engine_name} is missing."
end
- puts "[#{engine_name.capitalize} WARNING] Run `bundle exec rake railties:install:migrations` to get them.\n\n"
+ puts "[#{engine_name.capitalize} WARNING] Run `bundle exec rake spree:install:migrations` to get them.\n\n"
true
end
end
diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb
index 785e3d8f05..d9ef743c98 100644
--- a/core/lib/spree/testing_support/common_rake.rb
+++ b/core/lib/spree/testing_support/common_rake.rb
@@ -33,8 +33,6 @@ namespace :common do
system('bin/rails stimulus:install')
end
- system('bin/rake acts_as_taggable_on_engine:install:migrations > /dev/null 2>&1')
-
Spree::InstallGenerator.start [
"--lib_name=#{ENV['LIB_NAME']}",
'--auto-accept',