From 42cc1d298bcc2efe5ffa1c8922234e0371f0d549 Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Thu, 17 Sep 2026 10:49:58 +0200 Subject: [PATCH] sparkyfitness: start the server through the entrypoint that migrates The Better Auth CLI added in the previous commit is the wrong tool. It generates sso_provider.user_id as text and cannot reference this schema's uuid user.id: foreign key constraint "sso_provider_user_id_fkey" cannot be implemented [...] incompatible types: text and uuid The real cause is one line up in the unit. It ran tsx SparkyFitnessServer.js which imports the application module directly and never applies the schema migrations. Upstream starts through index.ts - nodemon.json has exec: tsx index.ts - and that file runs applyMigrations() and applyRlsPolicies() before importing anything, with a comment naming this exact failure: Better Auth validates the database schema eagerly, the moment betterAuth() is constructed at auth.ts module scope [...] When migrations ran later (from inside SparkyFitnessServer.ts) that check read the pre-migration schema on the first boot after an upgrade, so every /api/auth request failed until the container was restarted. Point both the install and the update at index.ts and drop the CLI call. index.ts exits non-zero when a migration fails, so systemd surfaces that instead of serving a broken login. --- ct/sparkyfitness.sh | 15 +-------------- install/sparkyfitness-install.sh | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/ct/sparkyfitness.sh b/ct/sparkyfitness.sh index b17d9e298..0ce3e2a0f 100644 --- a/ct/sparkyfitness.sh +++ b/ct/sparkyfitness.sh @@ -52,19 +52,6 @@ function update_script() { $STD pnpm install msg_ok "Updated Sparky Fitness Backend" - if [[ -f /opt/sparkyfitness/SparkyFitnessServer/auth.ts ]]; then - msg_info "Applying Better Auth Migrations" - cd /opt/sparkyfitness/SparkyFitnessServer - set -a - source /etc/sparkyfitness/.env - set +a - if $STD npx --yes @better-auth/cli migrate --config auth.ts -y; then - msg_ok "Applied Better Auth Migrations" - else - msg_warn "Better Auth migration failed - sign-in may report a schema mismatch until it is run by hand" - fi - fi - msg_info "Updating Sparky Fitness Frontend (Patience)" cd /opt/sparkyfitness $STD pnpm install @@ -99,7 +86,7 @@ function update_script() { Type=simple WorkingDirectory=/opt/sparkyfitness/SparkyFitnessServer EnvironmentFile=/etc/sparkyfitness/.env - ExecStart=/opt/sparkyfitness/SparkyFitnessServer/node_modules/.bin/tsx SparkyFitnessServer.js + ExecStart=/opt/sparkyfitness/SparkyFitnessServer/node_modules/.bin/tsx index.ts Restart=always RestartSec=5 diff --git a/install/sparkyfitness-install.sh b/install/sparkyfitness-install.sh index 0d04252de..ffb01de59 100644 --- a/install/sparkyfitness-install.sh +++ b/install/sparkyfitness-install.sh @@ -70,7 +70,7 @@ Requires=postgresql.service Type=simple WorkingDirectory=/opt/sparkyfitness/SparkyFitnessServer EnvironmentFile=/etc/sparkyfitness/.env -ExecStart=/opt/sparkyfitness/SparkyFitnessServer/node_modules/.bin/tsx SparkyFitnessServer.js +ExecStart=/opt/sparkyfitness/SparkyFitnessServer/node_modules/.bin/tsx index.ts Restart=always RestartSec=5