"""
Add service in table for incomplete posts
"""

from yoyo import step

__depends__ = {"20230408_00_FLSD-add-post-incomplete-rewards"}

steps = [
    step(
        """
        ALTER TABLE posts_incomplete_rewards ADD COLUMN "user" varchar(255) NULL;
        """
    ),
    step(
        """
        UPDATE posts_incomplete_rewards pir
        SET "user" = p."user"
        FROM posts p
        WHERE pir.id = p.id AND pir.service = p.service;
        """
    ),
    step(
        """
        CREATE INDEX posts_incomplete_rewards_service_user_idx ON posts_incomplete_rewards USING btree (service, "user");
        """
    ),
]
