From 56bfb08d0eab58bce522c9252cdf1377134fee8d Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Mon, 9 Feb 2026 14:27:30 -0800 Subject: [PATCH] attempts pt. 2 --- src/lib/db/client-db/index.ts | 5 ++++- src/lib/db/import-amq.ts | 4 +++- src/lib/db/{index.ts => server.ts} | 0 3 files changed, 7 insertions(+), 2 deletions(-) rename src/lib/db/{index.ts => server.ts} (100%) diff --git a/src/lib/db/client-db/index.ts b/src/lib/db/client-db/index.ts index 215822c..015e416 100644 --- a/src/lib/db/client-db/index.ts +++ b/src/lib/db/client-db/index.ts @@ -25,7 +25,10 @@ async function initDb() { } async function serverDb() { - const { initDb } = await import(".."); + if (!import.meta.env.SSR) return null; + const { building } = await import("$app/environment"); + if (building) return null; + const { initDb } = await import("../server"); return initDb(); } diff --git a/src/lib/db/import-amq.ts b/src/lib/db/import-amq.ts index c35352e..ac214f1 100644 --- a/src/lib/db/import-amq.ts +++ b/src/lib/db/import-amq.ts @@ -1,3 +1,4 @@ +import "dotenv/config"; import { eq } from "drizzle-orm"; import { z } from "zod"; import { @@ -12,7 +13,6 @@ import amqArtistsJson from "../../../data/amq-artists.json" with { }; import amqGroupsJson from "../../../data/amq-groups.json" with { type: "json" }; import amqSongsJson from "../../../data/amq-songs.json" with { type: "json" }; -import { db } from "./index"; import { anime, animeGenres, @@ -30,6 +30,7 @@ import { songs, tags, } from "./schema"; +import { initDb } from "./server"; /** * AMQ JSON import routine @@ -182,6 +183,7 @@ export async function importAmqData( } // 2) Apply inserts in a transaction + const db = await initDb(); db.transaction(() => { if (wipeFirst) { // Child tables first, then parents (respect FKs) diff --git a/src/lib/db/index.ts b/src/lib/db/server.ts similarity index 100% rename from src/lib/db/index.ts rename to src/lib/db/server.ts