This repository has been archived on 2024-05-29. You can view files and clone it, but cannot push or open issues or pull requests.
reset-sender-v2/drizzle/0000_icy_vulcan.sql
2024-03-05 11:21:09 +01:00

39 lines
1.1 KiB
SQL

DO $$ BEGIN
CREATE TYPE "status" AS ENUM('pending', 'success', 'error');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "letters" (
"id" serial PRIMARY KEY NOT NULL,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
"first_name" text NOT NULL,
"last_name" text NOT NULL,
"lang" text NOT NULL,
"email" text NOT NULL,
"phone" text NOT NULL,
"variant" text NOT NULL,
"gender" text,
"branch" text NOT NULL,
"is_client" boolean NOT NULL,
"message" text NOT NULL,
"is_subscribed" boolean NOT NULL,
"confirmation_token" text NOT NULL,
"is_confirmed" boolean DEFAULT false,
CONSTRAINT "letters_email_unique" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "messages" (
"id" serial PRIMARY KEY NOT NULL,
"letter_id" integer,
"from" text NOT NULL,
"to" text NOT NULL,
"status" "status" NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "messages" ADD CONSTRAINT "messages_letter_id_letters_id_fk" FOREIGN KEY ("letter_id") REFERENCES "letters"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;