そのプラグインは知りませんでした。便利ですね!私はそれをインストールしていませんが、データコンテナに入力してクエリを実行することはできます。
それは素晴らしい手がかりです!エラーメッセージを正しく読んでいるのであれば、theme_fields テーブルに関するものではないと思います。なぜなら、その特定のテーブルには theme_field_id がないからです。ソースコードは確認していませんが、add_index() の最初の引数はテーブル名で、2番目の引数はカラムだと推測します。
それを踏まえると、javascript_caches テーブルのようです。
== 20230817174049 EnsureJavascriptCacheIsUniquePerTheme: migrating ===========
-- remove_index(:javascript_caches, :theme_id)
-> 0.0208s
-- add_index(:javascript_caches, :theme_id, {:unique=>true})
-> 0.0079s
-- remove_index(:javascript_caches, :theme_field_id)
-> 0.0026s
-- add_index(:javascript_caches, :theme_field_id, {:unique=>true})
それで、そのテーブルの構造を確認したところ、theme_field_id カラムがありました。
discourse=# \d javascript_caches
Table "public.javascript_caches"
Column | Type | Collation | Nullable | Default
----------------+-----------------------------+-----------+----------+-----------------------------------------------
id | bigint | | not null | nextval('javascript_caches_id_seq'::regclass)
theme_field_id | bigint | | |
digest | character varying | | |
content | text | | not null |
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
theme_id | bigint | | |
source_map | text | | |
Indexes:
"javascript_caches_pkey" PRIMARY KEY, btree (id)
"index_javascript_caches_on_digest" btree (digest)
"index_javascript_caches_on_theme_field_id" btree (theme_field_id)
"index_javascript_caches_on_theme_id" btree (theme_id)
Check constraints:
"enforce_theme_or_theme_field" CHECK (theme_id IS NOT NULL AND theme_field_id IS NULL OR theme_id IS NULL AND theme_field_id IS NOT NULL)
Foreign-key constraints:
"fk_rails_58f94aecc4" FOREIGN KEY (theme_id) REFERENCES themes(id) ON DELETE CASCADE
"fk_rails_ed33506dbd" FOREIGN KEY (theme_field_id) REFERENCES theme_fields(id) ON DELETE CASCADE
そのテーブルをクエリすることができました(コンテンツフィールドは読み取れるように短縮しました)。重複があることがわかります。しかし、これらの重複が何を意味するのかはわかりません。
discourse=# select id, theme_field_id, digest, substring(content from 1 for 64) as content_64, created_at, updated_at, theme_id, substring(source_map from 1 for 64) as source_64 from javascript_caches where theme_field_id = 3;
id | theme_field_id | digest | content_64 | created_at | updated_at | theme_id | source_64
----+----------------+------------------------------------------+------------------------------------------------------------------+----------------------------+----------------------------+----------+------------------------------------------------------------------
1 | 3 | d0b6ec642d5649064ff0501cadc775a9217b16e0 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:56.606537 | 2023-08-18 20:47:19.596923 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
2 | 3 | 7fd74ecf4448afccdbcd9ccde87acddb4ec6f514 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:58.228209 | 2023-08-18 20:50:41.049209 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
コンテンツが見覚えがあったので、Customize → Theme → My Theme → Common → Head に移動し、マイナーな変更を加えて保存しました。すると、エントリの1つが更新され、もう1つは古いままになっていることがわかりました。
discourse=# select id, theme_field_id, digest, substring(content from 1 for 64) as content_64, created_at, updated_at, theme_id, substring(source_map from 1 for 64) as source_64 from javascript_caches where theme_field_id = 3;
id | theme_field_id | digest | content_64 | created_at | updated_at | theme_id | source_64
----+----------------+------------------------------------------+------------------------------------------------------------------+----------------------------+----------------------------+----------+------------------------------------------------------------------
2 | 3 | 7fd74ecf4448afccdbcd9ccde87acddb4ec6f514 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:58.228209 | 2023-08-18 20:50:41.049209 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
1 | 3 | 7f4132b1f9ced1b90b8f8fc24812cc11e81fea8d | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:56.606537 | 2023-09-13 21:56:56.312263 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
(2 rows)
ここでも、これらの重複が何を意味するのか、古い方を削除しても安全なのか、あるいはこれをクリーンアップできる「キャッシュの再構築」のような他の方法があるのかはわかりません。