summaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2024-11-24 12:51:57 +0100
committerWriterV2 <primary-v2@protonmail.com>2024-11-24 12:51:57 +0100
commit9a3db2b9fab5e5cfa34d921bbff9ad95dbf05ee6 (patch)
tree9b78d799d1ea4698f0c26f633486dfd82112b9e5 /migrations
parent364763e039b286774c29c4995df6baba9d22a61a (diff)
Fix: Make tags unique (empties product tags)
Diffstat (limited to 'migrations')
-rw-r--r--migrations/20241124111952_uniquetags.sql19
1 files changed, 19 insertions, 0 deletions
diff --git a/migrations/20241124111952_uniquetags.sql b/migrations/20241124111952_uniquetags.sql
new file mode 100644
index 0000000..ff8b6ef
--- /dev/null
+++ b/migrations/20241124111952_uniquetags.sql
@@ -0,0 +1,19 @@
+DELETE FROM producttag;
+CREATE TABLE IF NOT EXISTS newtag
+(
+ id INTEGER PRIMARY KEY NOT NULL,
+ name TEXT NOT NULL UNIQUE
+);
+
+WITH uniquetags AS (
+ SELECT id, name, ROW_NUMBER() OVER (PARTITION BY name ORDER BY id) AS row_num
+ FROM tag
+)
+
+INSERT INTO newtag (id, name)
+SELECT id, name
+FROM uniquetags
+WHERE row_num = 1;
+
+DROP TABLE tag;
+ALTER TABLE newtag RENAME TO tag;