From ec037a3bbd3a63917d7c53efd7cee4094103a605 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 20 Dec 2024 12:46:44 +0100 Subject: [PATCH] fix: error in schema --- .../{0000_clever_odin.sql => 0000_wakeful_zodiak.sql} | 2 +- store/drizzle/meta/0000_snapshot.json | 8 ++++---- store/drizzle/meta/_journal.json | 4 ++-- store/src/db/db.ts | 5 +++-- store/src/routes/node/node.schema.ts | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) rename store/drizzle/{0000_clever_odin.sql => 0000_wakeful_zodiak.sql} (83%) diff --git a/store/drizzle/0000_clever_odin.sql b/store/drizzle/0000_wakeful_zodiak.sql similarity index 83% rename from store/drizzle/0000_clever_odin.sql rename to store/drizzle/0000_wakeful_zodiak.sql index 95af691..bc250b5 100644 --- a/store/drizzle/0000_clever_odin.sql +++ b/store/drizzle/0000_wakeful_zodiak.sql @@ -15,7 +15,7 @@ CREATE TABLE "nodes" ( "previous" varchar(8) ); --> statement-breakpoint -ALTER TABLE "nodes" ADD CONSTRAINT "nodes_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +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 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 diff --git a/store/drizzle/meta/0000_snapshot.json b/store/drizzle/meta/0000_snapshot.json index c458c6e..36c2451 100644 --- a/store/drizzle/meta/0000_snapshot.json +++ b/store/drizzle/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "91f8730d-dd5a-4a25-b840-e42b0ef1bc72", + "id": "e0d14457-de6a-4832-80fd-ee24523ff95c", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", @@ -154,15 +154,15 @@ } }, "foreignKeys": { - "nodes_userId_users_id_fk": { - "name": "nodes_userId_users_id_fk", + "nodes_userId_users_name_fk": { + "name": "nodes_userId_users_name_fk", "tableFrom": "nodes", "tableTo": "users", "columnsFrom": [ "userId" ], "columnsTo": [ - "id" + "name" ], "onDelete": "no action", "onUpdate": "no action" diff --git a/store/drizzle/meta/_journal.json b/store/drizzle/meta/_journal.json index ba74048..20760b7 100644 --- a/store/drizzle/meta/_journal.json +++ b/store/drizzle/meta/_journal.json @@ -5,8 +5,8 @@ { "idx": 0, "version": "7", - "when": 1734694927055, - "tag": "0000_clever_odin", + "when": 1734695191817, + "tag": "0000_wakeful_zodiak", "breakpoints": true } ] diff --git a/store/src/db/db.ts b/store/src/db/db.ts index ae6992a..5fb68b6 100644 --- a/store/src/db/db.ts +++ b/store/src/db/db.ts @@ -16,6 +16,7 @@ export const db = drizzle({ schema, }); -export function migrateDb() { - return migrate(db, { migrationsFolder: "drizzle" }); +export async function migrateDb() { + await migrate(db, { migrationsFolder: "drizzle" }); + console.log("Database migrated"); } diff --git a/store/src/routes/node/node.schema.ts b/store/src/routes/node/node.schema.ts index 8579921..cd5fdc8 100644 --- a/store/src/routes/node/node.schema.ts +++ b/store/src/routes/node/node.schema.ts @@ -22,7 +22,7 @@ const bytea = customType<{ export const nodeTable = pgTable("nodes", { id: serial().primaryKey(), - userId: varchar().notNull().references(() => usersTable.id), + userId: varchar().notNull().references(() => usersTable.name), systemId: varchar().notNull(), nodeId: varchar().notNull(), content: bytea().notNull(),