attempts pt. 2

This commit is contained in:
2026-02-09 14:27:30 -08:00
parent 7f8dbcdc6b
commit 56bfb08d0e
3 changed files with 7 additions and 2 deletions

View File

@@ -25,7 +25,10 @@ async function initDb() {
} }
async function serverDb() { 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(); return initDb();
} }

View File

@@ -1,3 +1,4 @@
import "dotenv/config";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { z } from "zod"; import { z } from "zod";
import { import {
@@ -12,7 +13,6 @@ import amqArtistsJson from "../../../data/amq-artists.json" with {
}; };
import amqGroupsJson from "../../../data/amq-groups.json" with { type: "json" }; import amqGroupsJson from "../../../data/amq-groups.json" with { type: "json" };
import amqSongsJson from "../../../data/amq-songs.json" with { type: "json" }; import amqSongsJson from "../../../data/amq-songs.json" with { type: "json" };
import { db } from "./index";
import { import {
anime, anime,
animeGenres, animeGenres,
@@ -30,6 +30,7 @@ import {
songs, songs,
tags, tags,
} from "./schema"; } from "./schema";
import { initDb } from "./server";
/** /**
* AMQ JSON import routine * AMQ JSON import routine
@@ -182,6 +183,7 @@ export async function importAmqData(
} }
// 2) Apply inserts in a transaction // 2) Apply inserts in a transaction
const db = await initDb();
db.transaction(() => { db.transaction(() => {
if (wipeFirst) { if (wipeFirst) {
// Child tables first, then parents (respect FKs) // Child tables first, then parents (respect FKs)