Files
tidefront/packages/db/migrations/0002_ops.sql
T

69 lines
3.4 KiB
SQL

CREATE TABLE "backup_run" (
"id" serial PRIMARY KEY NOT NULL,
"file" text NOT NULL,
"bytes" bigint,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "mail_digest" (
"id" serial PRIMARY KEY NOT NULL,
"player_id" integer NOT NULL,
"kind" text NOT NULL,
"title" text NOT NULL,
"body" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"sent_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "password_reset" (
"id" serial PRIMARY KEY NOT NULL,
"player_id" integer NOT NULL,
"code_hash" text NOT NULL,
"via" text NOT NULL,
"created_by" integer,
"expires_at" timestamp with time zone NOT NULL,
"used_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "player_email" (
"player_id" integer PRIMARY KEY NOT NULL,
"email" text NOT NULL,
"verified_at" timestamp with time zone,
"verify_hash" text,
"verify_expires_at" timestamp with time zone,
"prefs" jsonb DEFAULT '{}'::jsonb NOT NULL,
"unsubscribe_token" text NOT NULL,
"last_digest_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "push_subscription" (
"id" serial PRIMARY KEY NOT NULL,
"player_id" integer NOT NULL,
"endpoint" text NOT NULL,
"p256dh" text NOT NULL,
"auth" text NOT NULL,
"prefs" jsonb DEFAULT '{}'::jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "server_setting" (
"key" text PRIMARY KEY NOT NULL,
"value" text NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "invite_code" ADD COLUMN "disabled_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "player" ADD COLUMN "is_admin" boolean DEFAULT false NOT NULL;--> statement-breakpoint
ALTER TABLE "player" ADD COLUMN "last_seen_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "mail_digest" ADD CONSTRAINT "mail_digest_player_id_player_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."player"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "password_reset" ADD CONSTRAINT "password_reset_player_id_player_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."player"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "player_email" ADD CONSTRAINT "player_email_player_id_player_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."player"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "push_subscription" ADD CONSTRAINT "push_subscription_player_id_player_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."player"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "mail_digest_open" ON "mail_digest" USING btree ("sent_at","player_id");--> statement-breakpoint
CREATE UNIQUE INDEX "password_reset_hash" ON "password_reset" USING btree ("code_hash");--> statement-breakpoint
CREATE INDEX "password_reset_player" ON "password_reset" USING btree ("player_id");--> statement-breakpoint
CREATE UNIQUE INDEX "player_email_unsub" ON "player_email" USING btree ("unsubscribe_token");--> statement-breakpoint
CREATE UNIQUE INDEX "push_subscription_endpoint" ON "push_subscription" USING btree ("endpoint");--> statement-breakpoint
CREATE INDEX "push_subscription_player" ON "push_subscription" USING btree ("player_id");