From 76c2e26e8cc561a8294ed2a6d9dec0f27a70e8a1 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 12:44:48 +0200 Subject: [PATCH 01/13] test persistent storage --- src/init/init_db.ts | 3 ++- src/lib/server/dbService.ts | 3 ++- src/routes/index.ts | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/init/init_db.ts b/src/init/init_db.ts index c158151..99ad5e3 100644 --- a/src/init/init_db.ts +++ b/src/init/init_db.ts @@ -1,8 +1,9 @@ import Database from 'better-sqlite3'; import fs from 'fs'; import path from 'path'; +import { DB_FULLPATH } from '../routes'; -const fullPath = './src/lib/data/tatort.db'; +const fullPath = DB_FULLPATH; const dir = path.dirname(fullPath); if (!fs.existsSync(dir)) { diff --git a/src/lib/server/dbService.ts b/src/lib/server/dbService.ts index 21f2c4c..e91cb4c 100644 --- a/src/lib/server/dbService.ts +++ b/src/lib/server/dbService.ts @@ -1,8 +1,9 @@ import Database from 'better-sqlite3'; import fs from 'fs'; import path from 'path'; +import { DB_FULLPATH } from '../../routes'; -const fullPath = './src/lib/data/tatort.db'; +const fullPath = DB_FULLPATH; const dir = path.dirname(fullPath); if (!fs.existsSync(dir)) { diff --git a/src/routes/index.ts b/src/routes/index.ts index 27df54c..c0ffe40 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -36,3 +36,6 @@ export const API_ROUTES = { USERS: '/api/users', USER: (userId: string) => `/api/users/${userId}` }; + +// './src/lib/data/tatort.db' +export const DB_FULLPATH = '/daten/tatort.db' From 5d6ac9438dd42529f7c19d136647d8a5a5ed83b0 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 12:58:54 +0200 Subject: [PATCH 02/13] testing PV: temporarily disable test creating dir --- tests/views/{Anmeldung.test.ts => Anmeldung.test.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/views/{Anmeldung.test.ts => Anmeldung.test.ts} (100%) diff --git a/tests/views/Anmeldung.test.ts b/tests/views/Anmeldung.test.ts similarity index 100% rename from tests/views/Anmeldung.test.ts rename to tests/views/Anmeldung.test.ts From 5128398516048d005fe59e323f3d9e4ab90f411f Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 13:10:02 +0200 Subject: [PATCH 03/13] add DB init during container start --- Dockerfile.dev | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile.dev b/Dockerfile.dev index cd5b2ea..21d1411 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -15,4 +15,5 @@ FROM node:24-alpine COPY --from=build /app . ENV HOST=0.0.0.0 EXPOSE 3000 +RUN npm run init-db CMD ["sh", "-c", "ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"] From 04b5aaa0dca679204fc0d7fa0f4cafc5779f3a37 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 13:31:12 +0200 Subject: [PATCH 04/13] testing PV: debug DB init script --- src/init/init_db.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init/init_db.ts b/src/init/init_db.ts index 99ad5e3..3401340 100644 --- a/src/init/init_db.ts +++ b/src/init/init_db.ts @@ -12,6 +12,7 @@ if (!fs.existsSync(dir)) { const db = new Database(fullPath); +console.log('xxx RUN') let createSQLStmt = `CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, From ddee170aea22b99035eedd8695d48aadd1a21436 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 13:41:46 +0200 Subject: [PATCH 05/13] testing: run DB init script before server start --- Dockerfile.dev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 21d1411..9c966b5 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -15,5 +15,5 @@ FROM node:24-alpine COPY --from=build /app . ENV HOST=0.0.0.0 EXPOSE 3000 -RUN npm run init-db +CMD ["sh", "-c", "npm run init-db"] CMD ["sh", "-c", "ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"] From b44bac760d8b23bf64bd73dd69769d61499eb843 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Mon, 13 Oct 2025 13:47:46 +0200 Subject: [PATCH 06/13] testing PV: remove DB init run during build --- Dockerfile.dev | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 9c966b5..5763159 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -8,7 +8,6 @@ RUN npm i --unsafe-perm COPY . ./ COPY config_dev.json ./config.json RUN npm run build -RUN npm run init-db # --- Production stage --- FROM node:24-alpine From c0a25c7a264219faac074c277ebd95c93f34df11 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 07:46:20 +0200 Subject: [PATCH 07/13] testing PV: run DB init before server run --- Dockerfile.dev | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 5763159..2c59f83 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -14,5 +14,4 @@ FROM node:24-alpine COPY --from=build /app . ENV HOST=0.0.0.0 EXPOSE 3000 -CMD ["sh", "-c", "npm run init-db"] -CMD ["sh", "-c", "ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"] +CMD ["sh", "-c", "npm run init-db && ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"] From 915153cb628ef171e43d39a3ad9d9c5223819aa9 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 08:15:08 +0200 Subject: [PATCH 08/13] testing PV: kick off build --- src/routes/(angemeldet)/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(angemeldet)/+page.svelte b/src/routes/(angemeldet)/+page.svelte index 8570c31..5d8de70 100644 --- a/src/routes/(angemeldet)/+page.svelte +++ b/src/routes/(angemeldet)/+page.svelte @@ -11,7 +11,7 @@

Pfad existiert: {data.path_existing}

+>

Pfad existiert --1 : {data.path_existing}

{#if data.user.admin}
From 3b0b9d724aaaffee3a91c09cd31e3098ef0e53c2 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 08:50:55 +0200 Subject: [PATCH 09/13] testing PV: kick off build --- src/routes/(angemeldet)/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/(angemeldet)/+page.svelte b/src/routes/(angemeldet)/+page.svelte index 5d8de70..54b4029 100644 --- a/src/routes/(angemeldet)/+page.svelte +++ b/src/routes/(angemeldet)/+page.svelte @@ -11,7 +11,7 @@

Pfad existiert --1 : {data.path_existing}

+>

Pfad existiert --A : {data.path_existing}

{#if data.user.admin}
From 9bf85c79e4a3f8b96c7e4ff324e8f42451e06b33 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 09:24:36 +0200 Subject: [PATCH 10/13] clean up, remove console.logs and debugging code --- src/init/init_db.ts | 1 - src/routes/(angemeldet)/+layout.server.ts | 22 +------------------ src/routes/(angemeldet)/+page.svelte | 2 +- src/routes/index.ts | 2 +- ...eldung.test.ts => Anmeldung.test.ts} | 0 tests/views/Layout.test.ts | 5 ++--- 6 files changed, 5 insertions(+), 27 deletions(-) rename tests/views/{Anmeldung.test.ts => Anmeldung.test.ts} (100%) diff --git a/src/init/init_db.ts b/src/init/init_db.ts index 3401340..99ad5e3 100644 --- a/src/init/init_db.ts +++ b/src/init/init_db.ts @@ -12,7 +12,6 @@ if (!fs.existsSync(dir)) { const db = new Database(fullPath); -console.log('xxx RUN') let createSQLStmt = `CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL UNIQUE, diff --git a/src/routes/(angemeldet)/+layout.server.ts b/src/routes/(angemeldet)/+layout.server.ts index 182068e..cdde090 100644 --- a/src/routes/(angemeldet)/+layout.server.ts +++ b/src/routes/(angemeldet)/+layout.server.ts @@ -3,30 +3,10 @@ import type { PageServerLoad } from '../anmeldung/$types'; import { ROUTE_NAMES } from '..'; -// *** [START] check for dir - -import fs from 'fs'; -const path = '/daten'; - -let path_existing: string; - -fs.access(path, fs.constants.F_OK, (err) => { - if (err) { - console.error(`❌ Directory "${path}" does NOT exist or is not accessible.`); - path_existing = "NO"; - } else { - console.log(`✅ Directory "${path}" exists and is accessible.`); - path_existing = "YES"; - } -}); - -// *** - export const load: PageServerLoad = (event: ServerLoadEvent) => { if (!event.locals.user && event.url.pathname !== ROUTE_NAMES.ANMELDUNG) throw redirect(303, ROUTE_NAMES.ANMELDUNG); return { - user: event.locals.user, - path_existing + user: event.locals.user }; }; diff --git a/src/routes/(angemeldet)/+page.svelte b/src/routes/(angemeldet)/+page.svelte index 54b4029..12431c8 100644 --- a/src/routes/(angemeldet)/+page.svelte +++ b/src/routes/(angemeldet)/+page.svelte @@ -11,7 +11,7 @@

Pfad existiert --A : {data.path_existing}

+>
{#if data.user.admin}
diff --git a/src/routes/index.ts b/src/routes/index.ts index c0ffe40..944a4cb 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -37,5 +37,5 @@ export const API_ROUTES = { USER: (userId: string) => `/api/users/${userId}` }; -// './src/lib/data/tatort.db' +// local database path: './src/lib/data/tatort.db' export const DB_FULLPATH = '/daten/tatort.db' diff --git a/tests/views/Anmeldung.test.ts b/tests/views/Anmeldung.test.ts similarity index 100% rename from tests/views/Anmeldung.test.ts rename to tests/views/Anmeldung.test.ts diff --git a/tests/views/Layout.test.ts b/tests/views/Layout.test.ts index 0c940f8..0f329ef 100644 --- a/tests/views/Layout.test.ts +++ b/tests/views/Layout.test.ts @@ -22,9 +22,8 @@ describe('+layout.server load(): Teste korrekte URL', () => { }); describe('+layout.server load(): Teste erfolgreichen Pfad', () => { - // [TODO] - test.skip('Werfe kein Fehler', async () => { + test('Werfe kein Fehler', async () => { const result = load(mockEvent); expect(result).toEqual({ user: baseData.user }); }); -}); +}); \ No newline at end of file From 5082e6d52602bb7f80196ca457cece5dae377998 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 09:40:23 +0200 Subject: [PATCH 11/13] select path for DB depending on local or dev environment --- src/routes/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index 944a4cb..de5bac1 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,3 +1,5 @@ +import { dev } from '$app/environment'; + export const ROUTE_NAMES = { ROOT: '/', @@ -37,5 +39,4 @@ export const API_ROUTES = { USER: (userId: string) => `/api/users/${userId}` }; -// local database path: './src/lib/data/tatort.db' -export const DB_FULLPATH = '/daten/tatort.db' +export const DB_FULLPATH = dev ? './src/lib/data/tatort.db' : '/daten/tatort.db' \ No newline at end of file From 662211e1c3295db03192e20dbc88b1d11d315d13 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 09:48:04 +0200 Subject: [PATCH 12/13] make sure the DB is initiated --- src/lib/server/dbService.ts | 12 +++--------- src/routes/index.ts | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/lib/server/dbService.ts b/src/lib/server/dbService.ts index e91cb4c..d50bee5 100644 --- a/src/lib/server/dbService.ts +++ b/src/lib/server/dbService.ts @@ -1,13 +1,7 @@ import Database from 'better-sqlite3'; -import fs from 'fs'; -import path from 'path'; import { DB_FULLPATH } from '../../routes'; -const fullPath = DB_FULLPATH; -const dir = path.dirname(fullPath); +// make sure the DB is initiated +import '../../init/init_db' -if (!fs.existsSync(dir)) { - fs.mkdirSync(dir); -} - -export const db = new Database(fullPath); +export const db = new Database(DB_FULLPATH); diff --git a/src/routes/index.ts b/src/routes/index.ts index de5bac1..db87d01 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -39,4 +39,4 @@ export const API_ROUTES = { USER: (userId: string) => `/api/users/${userId}` }; -export const DB_FULLPATH = dev ? './src/lib/data/tatort.db' : '/daten/tatort.db' \ No newline at end of file +export const DB_FULLPATH = dev ? './src/lib/data/tatort.db' : '/daten/tatort.db'; \ No newline at end of file From 549ea896c7d6f1a95ce394634e29da16267d8b82 Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 14 Oct 2025 10:39:07 +0200 Subject: [PATCH 13/13] select storage path depending on local testing or prod --- src/routes/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index db87d01..a8c3603 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,5 +1,3 @@ -import { dev } from '$app/environment'; - export const ROUTE_NAMES = { ROOT: '/', @@ -39,4 +37,5 @@ export const API_ROUTES = { USER: (userId: string) => `/api/users/${userId}` }; -export const DB_FULLPATH = dev ? './src/lib/data/tatort.db' : '/daten/tatort.db'; \ No newline at end of file +const isProd = process.env.NODE_ENV == 'production'; +export const DB_FULLPATH = !isProd ? './src/lib/data/tatort.db' : '/daten/tatort.db'; \ No newline at end of file