Files
plp/prisma/migrations/0011_safety_admin_notification/migration.sql
T

17 lines
1.2 KiB
SQL

CREATE TYPE "AccountRole" AS ENUM ('USER', 'ADMIN');
ALTER TABLE "accounts" ADD COLUMN "role" "AccountRole" NOT NULL DEFAULT 'USER';
ALTER TABLE "reports" ADD COLUMN "idempotency_key" VARCHAR(128) DEFAULT gen_random_uuid()::text;
UPDATE "reports" SET "idempotency_key" = "id"::text WHERE "idempotency_key" IS NULL;
ALTER TABLE "reports" ALTER COLUMN "idempotency_key" SET NOT NULL;
CREATE UNIQUE INDEX "reports_reporter_id_idempotency_key_key" ON "reports"("reporter_id", "idempotency_key");
ALTER TABLE "notifications" ADD COLUMN "dedupe_key" VARCHAR(255);
UPDATE "notifications" SET "dedupe_key" = "id"::text WHERE "dedupe_key" IS NULL;
ALTER TABLE "notifications" ALTER COLUMN "dedupe_key" SET NOT NULL;
CREATE UNIQUE INDEX "notifications_account_id_dedupe_key_key" ON "notifications"("account_id", "dedupe_key");
CREATE TABLE "push_preferences" (
"account_id" UUID NOT NULL,
"in_app_enabled" BOOLEAN NOT NULL DEFAULT true,
"updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "push_preferences_pkey" PRIMARY KEY ("account_id"),
CONSTRAINT "push_preferences_account_id_fkey" FOREIGN KEY ("account_id") REFERENCES "accounts"("id") ON DELETE CASCADE ON UPDATE CASCADE
);