"""
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);
        """
    ),
]
