109 lines
5.9 KiB
SQL
109 lines
5.9 KiB
SQL
CREATE TYPE "public"."activity_status" AS ENUM('idle', 'in_flight');--> statement-breakpoint
|
|
CREATE TYPE "public"."board_kind" AS ENUM('bay', 'tutorial');--> statement-breakpoint
|
|
CREATE TYPE "public"."dispatch_status" AS ENUM('in_flight', 'resolved');--> statement-breakpoint
|
|
CREATE TABLE "accepted_contracts" (
|
|
"player_id" text NOT NULL,
|
|
"contract_id" text NOT NULL,
|
|
"period_index" integer NOT NULL,
|
|
"dispatch_id" text NOT NULL,
|
|
"accepted_at" bigint NOT NULL,
|
|
CONSTRAINT "accepted_contracts_player_id_contract_id_pk" PRIMARY KEY("player_id","contract_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "bays" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"location_id" text NOT NULL,
|
|
"created_at" bigint NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "companies" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"credits" bigint NOT NULL,
|
|
CONSTRAINT "companies_player_id_unique" UNIQUE("player_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "contract_boards" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"kind" "board_kind" NOT NULL,
|
|
"location_id" text NOT NULL,
|
|
"period_index" integer NOT NULL,
|
|
"contracts" jsonb NOT NULL,
|
|
"created_at" bigint NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "discovered_locations" (
|
|
"player_id" text NOT NULL,
|
|
"location_id" text NOT NULL,
|
|
"discovered_at" bigint NOT NULL,
|
|
CONSTRAINT "discovered_locations_player_id_location_id_pk" PRIMARY KEY("player_id","location_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "dispatches" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"ship_id" text,
|
|
"pilot_id" text NOT NULL,
|
|
"tutorial" boolean NOT NULL,
|
|
"record" jsonb NOT NULL,
|
|
"arrival_at" bigint NOT NULL,
|
|
"status" "dispatch_status" DEFAULT 'in_flight' NOT NULL,
|
|
"resolution" jsonb,
|
|
"resolved_at" bigint,
|
|
"acknowledged_at" bigint
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "pilots" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"is_avatar" boolean DEFAULT false NOT NULL,
|
|
"xp" integer DEFAULT 0 NOT NULL,
|
|
"skills" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
"skill_points_spent" integer DEFAULT 0 NOT NULL,
|
|
"assigned_ship_id" text,
|
|
"location_id" text,
|
|
"status" "activity_status" DEFAULT 'idle' NOT NULL,
|
|
"created_at" bigint NOT NULL,
|
|
CONSTRAINT "pilots_assigned_ship_id_unique" UNIQUE("assigned_ship_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "players" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"world_seed" bigint NOT NULL,
|
|
"tutorial_active" boolean DEFAULT true NOT NULL,
|
|
"loaner_location_id" text,
|
|
"created_at" bigint NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "ships" (
|
|
"id" text PRIMARY KEY NOT NULL,
|
|
"player_id" text NOT NULL,
|
|
"model_id" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"status" "activity_status" DEFAULT 'idle' NOT NULL,
|
|
"location_id" text,
|
|
"created_at" bigint NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "accepted_contracts" ADD CONSTRAINT "accepted_contracts_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "accepted_contracts" ADD CONSTRAINT "accepted_contracts_dispatch_id_dispatches_id_fk" FOREIGN KEY ("dispatch_id") REFERENCES "public"."dispatches"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "bays" ADD CONSTRAINT "bays_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "companies" ADD CONSTRAINT "companies_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "contract_boards" ADD CONSTRAINT "contract_boards_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "discovered_locations" ADD CONSTRAINT "discovered_locations_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "dispatches" ADD CONSTRAINT "dispatches_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "dispatches" ADD CONSTRAINT "dispatches_ship_id_ships_id_fk" FOREIGN KEY ("ship_id") REFERENCES "public"."ships"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "dispatches" ADD CONSTRAINT "dispatches_pilot_id_pilots_id_fk" FOREIGN KEY ("pilot_id") REFERENCES "public"."pilots"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "pilots" ADD CONSTRAINT "pilots_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "pilots" ADD CONSTRAINT "pilots_assigned_ship_id_ships_id_fk" FOREIGN KEY ("assigned_ship_id") REFERENCES "public"."ships"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "ships" ADD CONSTRAINT "ships_player_id_players_id_fk" FOREIGN KEY ("player_id") REFERENCES "public"."players"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "bays_player_location_idx" ON "bays" USING btree ("player_id","location_id");--> statement-breakpoint
|
|
CREATE UNIQUE INDEX "contract_boards_unique_idx" ON "contract_boards" USING btree ("player_id","kind","location_id","period_index");--> statement-breakpoint
|
|
CREATE INDEX "dispatches_due_idx" ON "dispatches" USING btree ("status","arrival_at");--> statement-breakpoint
|
|
CREATE INDEX "dispatches_player_status_idx" ON "dispatches" USING btree ("player_id","status");--> statement-breakpoint
|
|
CREATE INDEX "pilots_player_idx" ON "pilots" USING btree ("player_id");--> statement-breakpoint
|
|
CREATE INDEX "ships_player_idx" ON "ships" USING btree ("player_id"); |