-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14-unique-hash-indexes.sql
26 lines (25 loc) · 1018 Bytes
/
14-unique-hash-indexes.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- HACK: This migration is commented out, because it's turned out to be
-- trouble. But, removing it from the sequence entirely also causes trouble.
-- So, this is a no-op.
--
-- The unique constraint got left out of an earlier actioncounters migration,
-- so this schematic migration forcibly cleans up the few duplicates and adds
-- the unique constraint.
--
-- There should only be about 50 duplicates in 180000 or so production records.
--
-- CREATE TEMPORARY TABLE dup_actioncounter_hashes
-- SELECT unique_hash
-- FROM actioncounters_actioncounterunique
-- GROUP BY unique_hash
-- HAVING count(unique_hash) > 1;
--
-- DELETE FROM actioncounters_actioncounterunique
-- WHERE unique_hash IN
-- (SELECT unique_hash FROM dup_actioncounter_hashes);
--
-- DROP INDEX actioncounters_actioncounterunique_unique
-- ON actioncounters_actioncounterunique;
--
-- ALTER TABLE actioncounters_actioncounterunique
-- ADD UNIQUE actioncounters_actioncounterunique_unique (unique_hash);