#!/bin/sh set -e # Check if database exists and has data if [ -f /data/deardiary.db ]; then # Database exists - ensure migration tracking exists bun -e " const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient({ datasourceUrl: 'file:/data/deardiary.db' }); async function main() { try { const tables = await prisma.\$queryRaw\`SELECT name FROM sqlite_master WHERE type='table' AND name='_prisma_migrations'\`; if (tables.length === 0) { await prisma.\$executeRaw\` CREATE TABLE _prisma_migrations ( id TEXT PRIMARY KEY, checksum TEXT NOT NULL, finished_at DATETIME, migration_name TEXT NOT NULL, logs TEXT, rolled_back_at DATETIME, started_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, applied_steps_count INTEGER NOT NULL DEFAULT 0 ) \`; await prisma.\$executeRaw\`INSERT INTO _prisma_migrations (id, checksum, finished_at, migration_name, applied_steps_count) VALUES (lower(hex(randomblob(16))), 'baseline', datetime('now'), '00000000000000_init', 1)\`; console.log('Migration table created'); } } catch (e) { console.log('Migration check done'); } await prisma.\$disconnect(); } main(); " fi echo "Starting server..." nginx -g 'daemon off;' & exec bun ./dist/index.js