FIX: Clean broken relations before adding javascript_caches foreign key
This commit is contained in:
parent
6ad58913c8
commit
6afd7f0eae
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
class AddThemeIdToJavascriptCache < ActiveRecord::Migration[5.2]
|
class AddThemeIdToJavascriptCache < ActiveRecord::Migration[5.2]
|
||||||
def up
|
def up
|
||||||
|
# Delete any javascript caches with broken foreign keys
|
||||||
|
execute <<~SQL
|
||||||
|
DELETE FROM javascript_caches jc
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM theme_fields tf
|
||||||
|
WHERE tf.id = jc.theme_field_id
|
||||||
|
);
|
||||||
|
SQL
|
||||||
make_changes
|
make_changes
|
||||||
execute "ALTER TABLE javascript_caches ADD CONSTRAINT 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))"
|
execute "ALTER TABLE javascript_caches ADD CONSTRAINT 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))"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue