nodes/store/drizzle/0000_known_kid_colt.sql

25 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

2024-12-20 12:42:45 +01:00
CREATE TABLE "users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"name" text NOT NULL,
CONSTRAINT "users_name_unique" UNIQUE("name")
);
--> statement-breakpoint
CREATE TABLE "nodes" (
"id" serial PRIMARY KEY NOT NULL,
"userId" varchar NOT NULL,
2024-12-20 15:24:54 +01:00
"createdAt" timestamp DEFAULT now(),
2024-12-20 12:42:45 +01:00
"systemId" varchar NOT NULL,
"nodeId" varchar NOT NULL,
"content" "bytea" NOT NULL,
"definition" json NOT NULL,
2024-12-20 15:24:54 +01:00
"hash" varchar(16) NOT NULL,
"previous" varchar(16),
2024-12-20 12:49:25 +01:00
CONSTRAINT "nodes_hash_unique" UNIQUE("hash")
2024-12-20 12:42:45 +01:00
);
--> statement-breakpoint
2024-12-20 12:46:44 +01:00
ALTER TABLE "nodes" ADD CONSTRAINT "nodes_userId_users_name_fk" FOREIGN KEY ("userId") REFERENCES "public"."users"("name") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
2024-12-20 12:42:45 +01:00
ALTER TABLE "nodes" ADD CONSTRAINT "node_previous_fk" FOREIGN KEY ("previous") REFERENCES "public"."nodes"("hash") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "user_id_idx" ON "nodes" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "system_id_idx" ON "nodes" USING btree ("systemId");--> statement-breakpoint
CREATE INDEX "node_id_idx" ON "nodes" USING btree ("nodeId");--> statement-breakpoint
CREATE INDEX "hash_idx" ON "nodes" USING btree ("hash");