kemono2/db/migrations/20231015_20_2f3f4i-remove-duplicate-flags.py

22 lines
572 B
Python
Raw Permalink Normal View History

2024-07-04 22:08:17 +02:00
"""
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);
"""
),
]