kemono2/db/migrations/20231015_20_2f3f4i-remove-duplicate-flags.py
2024-07-04 21:57:05 +02:00

22 lines
572 B
Python

"""
Remove duplicate flags since there is no restriction
"""
from yoyo import step
__depends__ = {"20210118_01_1Jlkq-add-unique-constraint-to-service-and-post-fields"}
steps = [
step(
"""
DELETE FROM public.booru_flags T1
using public.booru_flags T2
WHERE T1.ctid > T2.ctid AND T1.id = T2.id AND T1."user" = T2."user" AND T1.service = T2.service;
DROP INDEX IF EXISTS flag_id_idx, flag_service_idx, flag_user_idx;
ALTER TABLE booru_flags ADD PRIMARY KEY (id, "user", service);
"""
),
]