Files
database/migrations/archive/000.411.sql
T
Rikard BartholfandGitHub ddcbd0afb0 Archive old migrations (#426)
* Archive old migrations

* Fix invalid placement of migrations
2024-10-17 11:19:12 +02:00

19 lines
794 B
SQL

-- Add unique keyword_i18n locale constraint
-- First we have to delete the duplicates that already exists (keywords 1316-1326; 138 keywords_i18n entries)
with duplicates as (
select duplicate.id duplicate_id, *
from keywords_i18n first
-- inner join the same table where keyword_id, locale_id AND value must all be the same,
-- i.e. only duplicate translations with the same translated value will be included
join keywords_i18n duplicate using (keyword_id, locale_id, value)
where first.id <> duplicate.id
-- only include the last copy, so we dont delete the original
and duplicate.id > first.id
) delete from keywords_i18n where id in (select duplicate_id from duplicates);
-- Now we are allowed to add our constraint
ALTER TABLE keywords_i18n ADD UNIQUE (keyword_id, locale_id);