Skip to content
Source
Sign inSign up
samwillis/neonbricks
Open History to see the last commit

0000_sour_jane_foster.sql

142 lines7.7 KB

1CREATE TABLE "spatial_buckets" (
2 "world" uuid NOT NULL,
3 "x" integer NOT NULL,
4 "y" integer NOT NULL,
5 "z" integer NOT NULL,
6 CONSTRAINT "spatial_buckets_world_x_y_z_pk" PRIMARY KEY("world","x","y","z")
7);
8--> statement-breakpoint
9CREATE TABLE "connector_slot_claims" (
10 "world" uuid NOT NULL,
11 "part" uuid NOT NULL,
12 "slot" text NOT NULL,
13 "connection" uuid NOT NULL,
14 CONSTRAINT "connector_slot_claims_world_part_slot_pk" PRIMARY KEY("world","part","slot")
15);
16--> statement-breakpoint
17CREATE TABLE "part_connections" (
18 "id" uuid PRIMARY KEY NOT NULL,
19 "world" uuid NOT NULL,
20 "a" uuid NOT NULL,
21 "b" uuid NOT NULL,
22 "ca" text NOT NULL,
23 "cb" text NOT NULL,
24 "revision" integer NOT NULL,
25 "deleted" integer DEFAULT 0 NOT NULL
26);
27--> statement-breakpoint
28CREATE TABLE "guests" (
29 "id" uuid PRIMARY KEY NOT NULL,
30 "name" text NOT NULL,
31 "color" text NOT NULL
32);
33--> statement-breakpoint
34CREATE TABLE "guest_world_history" (
35 "world" uuid NOT NULL,
36 "guest" uuid NOT NULL,
37 "generation" integer NOT NULL,
38 "undo" jsonb DEFAULT '[]'::jsonb NOT NULL,
39 "redo" jsonb DEFAULT '[]'::jsonb NOT NULL,
40 CONSTRAINT "guest_world_history_world_guest_pk" PRIMARY KEY("world","guest")
41);
42--> statement-breakpoint
43CREATE TABLE "world_memberships" (
44 "world" uuid NOT NULL,
45 "guest" uuid NOT NULL,
46 "role" text DEFAULT 'editor' NOT NULL,
47 "active" integer DEFAULT 1 NOT NULL,
48 CONSTRAINT "world_memberships_world_guest_pk" PRIMARY KEY("world","guest")
49);
50--> statement-breakpoint
51CREATE TABLE "build_operations" (
52 "world" uuid NOT NULL,
53 "guest" uuid NOT NULL,
54 "id" uuid NOT NULL,
55 "generation" integer NOT NULL,
56 "digest" text NOT NULL,
57 "receipt" jsonb,
58 "before" jsonb,
59 "after" jsonb,
60 "before_connections" jsonb,
61 "after_connections" jsonb,
62 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
63 CONSTRAINT "build_operations_world_guest_id_pk" PRIMARY KEY("world","guest","id")
64);
65--> statement-breakpoint
66CREATE TABLE "part_instances" (
67 "id" uuid PRIMARY KEY NOT NULL,
68 "world" uuid NOT NULL,
69 "key" text NOT NULL,
70 "color" text NOT NULL,
71 "x" integer NOT NULL,
72 "y" integer NOT NULL,
73 "z" integer NOT NULL,
74 "rotation" integer NOT NULL,
75 "revision" integer NOT NULL,
76 "deleted" integer DEFAULT 0 NOT NULL,
77 "minx" integer NOT NULL,
78 "miny" integer NOT NULL,
79 "minz" integer NOT NULL,
80 "maxx" integer NOT NULL,
81 "maxy" integer NOT NULL,
82 "maxz" integer NOT NULL
83);
84--> statement-breakpoint
85CREATE TABLE "guest_sessions" (
86 "id" uuid PRIMARY KEY NOT NULL,
87 "guest" uuid NOT NULL,
88 "hash" text NOT NULL,
89 "expires_at" timestamp with time zone NOT NULL,
90 "absolute_expiry" timestamp with time zone NOT NULL,
91 "revoked" integer DEFAULT 0 NOT NULL,
92 CONSTRAINT "guest_sessions_hash_unique" UNIQUE("hash")
93);
94--> statement-breakpoint
95CREATE TABLE "viewer_sessions" (
96 "id" uuid PRIMARY KEY NOT NULL,
97 "world" uuid NOT NULL,
98 "guest" uuid NOT NULL,
99 "session" uuid NOT NULL,
100 "generation" integer NOT NULL,
101 "selection" jsonb DEFAULT '[]'::jsonb NOT NULL,
102 "preview" jsonb,
103 "sequence" integer DEFAULT 0 NOT NULL,
104 "preview_at" timestamp with time zone,
105 "expires_at" timestamp with time zone NOT NULL
106);
107--> statement-breakpoint
108CREATE TABLE "worlds" (
109 "id" uuid PRIMARY KEY NOT NULL,
110 "slug" text NOT NULL,
111 "title" text NOT NULL,
112 "owner" uuid,
113 "generation" integer DEFAULT 1 NOT NULL,
114 "catalogue" text NOT NULL,
115 "status" text DEFAULT 'open' NOT NULL,
116 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
117 CONSTRAINT "worlds_slug_unique" UNIQUE("slug")
118);
119--> statement-breakpoint
120ALTER TABLE "spatial_buckets" ADD CONSTRAINT "spatial_buckets_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
121ALTER TABLE "connector_slot_claims" ADD CONSTRAINT "connector_slot_claims_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
122ALTER TABLE "connector_slot_claims" ADD CONSTRAINT "connector_slot_claims_part_part_instances_id_fk" FOREIGN KEY ("part") REFERENCES "public"."part_instances"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
123ALTER TABLE "connector_slot_claims" ADD CONSTRAINT "connector_slot_claims_connection_part_connections_id_fk" FOREIGN KEY ("connection") REFERENCES "public"."part_connections"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
124ALTER TABLE "part_connections" ADD CONSTRAINT "part_connections_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
125ALTER TABLE "part_connections" ADD CONSTRAINT "part_connections_a_part_instances_id_fk" FOREIGN KEY ("a") REFERENCES "public"."part_instances"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
126ALTER TABLE "part_connections" ADD CONSTRAINT "part_connections_b_part_instances_id_fk" FOREIGN KEY ("b") REFERENCES "public"."part_instances"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
127ALTER TABLE "guest_world_history" ADD CONSTRAINT "guest_world_history_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
128ALTER TABLE "guest_world_history" ADD CONSTRAINT "guest_world_history_guest_guests_id_fk" FOREIGN KEY ("guest") REFERENCES "public"."guests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
129ALTER TABLE "world_memberships" ADD CONSTRAINT "world_memberships_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
130ALTER TABLE "world_memberships" ADD CONSTRAINT "world_memberships_guest_guests_id_fk" FOREIGN KEY ("guest") REFERENCES "public"."guests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
131ALTER TABLE "build_operations" ADD CONSTRAINT "build_operations_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
132ALTER TABLE "build_operations" ADD CONSTRAINT "build_operations_guest_guests_id_fk" FOREIGN KEY ("guest") REFERENCES "public"."guests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
133ALTER TABLE "part_instances" ADD CONSTRAINT "part_instances_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
134ALTER TABLE "guest_sessions" ADD CONSTRAINT "guest_sessions_guest_guests_id_fk" FOREIGN KEY ("guest") REFERENCES "public"."guests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
135ALTER TABLE "viewer_sessions" ADD CONSTRAINT "viewer_sessions_world_worlds_id_fk" FOREIGN KEY ("world") REFERENCES "public"."worlds"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
136ALTER TABLE "viewer_sessions" ADD CONSTRAINT "viewer_sessions_guest_guests_id_fk" FOREIGN KEY ("guest") REFERENCES "public"."guests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
137ALTER TABLE "viewer_sessions" ADD CONSTRAINT "viewer_sessions_session_guest_sessions_id_fk" FOREIGN KEY ("session") REFERENCES "public"."guest_sessions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
138CREATE UNIQUE INDEX "connection_pair" ON "part_connections" USING btree ("world","a","b","ca","cb");--> statement-breakpoint
139CREATE INDEX "connections_a" ON "part_connections" USING btree ("world","a");--> statement-breakpoint
140CREATE INDEX "connections_b" ON "part_connections" USING btree ("world","b");--> statement-breakpoint
141CREATE INDEX "parts_world_bounds" ON "part_instances" USING btree ("world","minx","maxx") WHERE "part_instances"."deleted"=0;--> statement-breakpoint
142CREATE INDEX "viewers_expiry" ON "viewer_sessions" USING btree ("world","expires_at");