diff --git a/app/models/javascript_cache.rb b/app/models/javascript_cache.rb index 794a4ef612d..1ebfbec15bd 100644 --- a/app/models/javascript_cache.rb +++ b/app/models/javascript_cache.rb @@ -46,8 +46,8 @@ end # Indexes # # index_javascript_caches_on_digest (digest) -# index_javascript_caches_on_theme_field_id (theme_field_id) -# index_javascript_caches_on_theme_id (theme_id) +# index_javascript_caches_on_theme_field_id (theme_field_id) UNIQUE +# index_javascript_caches_on_theme_id (theme_id) UNIQUE # # Foreign Keys # diff --git a/db/migrate/20230817174049_ensure_javascript_cache_is_unique_per_theme.rb b/db/migrate/20230817174049_ensure_javascript_cache_is_unique_per_theme.rb new file mode 100644 index 00000000000..ea60d36451c --- /dev/null +++ b/db/migrate/20230817174049_ensure_javascript_cache_is_unique_per_theme.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class EnsureJavascriptCacheIsUniquePerTheme < ActiveRecord::Migration[7.0] + def change + remove_index :javascript_caches, :theme_id + add_index :javascript_caches, :theme_id, unique: true + + remove_index :javascript_caches, :theme_field_id + add_index :javascript_caches, :theme_field_id, unique: true + end +end