From 80a0d88e4cb74c764a2afe5e0f4aa67da893fc4d Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Thu, 17 Aug 2023 13:57:04 -0500 Subject: [PATCH] FIX: Ensure javascript caches are unique per theme/theme_field (#23126) We were assuming that this was the case before, but not enforcing it. --- app/models/javascript_cache.rb | 4 ++-- ...049_ensure_javascript_cache_is_unique_per_theme.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230817174049_ensure_javascript_cache_is_unique_per_theme.rb 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