Files
glenloch-media/drizzle/0010_friendly_oracle.sql
2026-11-20 04:07:02 +00:00

37 lines
2.1 KiB
SQL

CREATE TABLE "notifications" (
"id" text PRIMARY KEY NOT NULL,
"user_id" text NOT NULL,
"channel" text DEFAULT 'email' NOT NULL,
"template_key" text NOT NULL,
"rule_key" text,
"assignment_id" text,
"slot_id" text,
"to_address" text NOT NULL,
"payload_json" text DEFAULT '' NOT NULL,
"dedupe_key" text NOT NULL,
"scheduled_for" timestamp with time zone DEFAULT now() NOT NULL,
"status" text DEFAULT 'queued' NOT NULL,
"attempts" integer DEFAULT 0 NOT NULL,
"provider_id" text,
"provider_status" text,
"error" text,
"sent_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone,
CONSTRAINT "notifications_dedupe_key_unique" UNIQUE("dedupe_key")
);
--> statement-breakpoint
CREATE TABLE "used_tokens" (
"jti" text PRIMARY KEY NOT NULL,
"assignment_id" text NOT NULL,
"action" text NOT NULL,
"used_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_assignment_id_assignments_id_fk" FOREIGN KEY ("assignment_id") REFERENCES "public"."assignments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_slot_id_slots_id_fk" FOREIGN KEY ("slot_id") REFERENCES "public"."slots"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "used_tokens" ADD CONSTRAINT "used_tokens_assignment_id_assignments_id_fk" FOREIGN KEY ("assignment_id") REFERENCES "public"."assignments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "notifications_status_scheduled_idx" ON "notifications" USING btree ("status","scheduled_for");--> statement-breakpoint
CREATE INDEX "notifications_user_idx" ON "notifications" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "notifications_assignment_idx" ON "notifications" USING btree ("assignment_id");