From ba87729be7fa270c6331f78c709f4800095cf526 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 17 Sep 2026 13:39:36 +0200 Subject: [PATCH] sparkyfitness: run the Better Auth migration during the update (#17318) * sparkyfitness: run the Better Auth migration during the update 1.7.1 ships a Better Auth version whose schema has columns 1.6.5 never created, and nothing in the update adds them. The backend starts, then refuses every sign-in: Database schema mismatch Missing columns session.impersonated_by two_factor.verified ... Run `npx auth migrate` to add the missing tables and columns. Run exactly that after the backend dependencies are in place, with the config Better Auth looks for, SparkyFitnessServer/auth.ts, and the database credentials from /etc/sparkyfitness/.env. Users who hit this were left running the server by hand to get the columns created. A failure warns instead of aborting: the rest of the update has already succeeded at that point, and the message names the remaining step. * 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 | 2 +- install/sparkyfitness-install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ct/sparkyfitness.sh b/ct/sparkyfitness.sh index 0daa9888b..0ce3e2a0f 100644 --- a/ct/sparkyfitness.sh +++ b/ct/sparkyfitness.sh @@ -86,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