kemono2/db/migrations/20250328_01_KV3ap-add-reason-to-flags.py
2025-04-11 00:58:59 +02:00

32 lines
1.1 KiB
Python

"""
Create new post_flags table.
"""
from yoyo import step
__depends__ = {"20241110_00_DASAD-add-favorite-counts-table"}
steps = [
step("""
CREATE TABLE "public"."post_flags" (
"post_id" TEXT NOT NULL,
"creator_id" TEXT NOT NULL,
"service" TEXT NOT NULL,
"contributor_id" int4 NOT NULL,
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
"reason" int2 NOT NULL,
"reason_text" TEXT,
"flagger_ip_hash" UUID,
CONSTRAINT "post_flags_pk" PRIMARY KEY ("post_id", "creator_id", "service", "contributor_id")
);
""", 'DROP TABLE "public"."post_flags"'),
step(
"""CREATE INDEX "idx_post_flags_on_contributor_id_and_created_at" ON "post_flags" ("contributor_id", "created_at");""",
"""DROP INDEX "idx_post_flags_on_contributor_id_and_created_at";"""
),
step(
"""CREATE INDEX "idx_post_flags_on_ip_hash_and_created_at" ON "post_flags" ("flagger_ip_hash", "created_at");""",
"""DROP INDEX "idx_post_flags_on_ip_hash_and_created_at";"""
),
]