Compare commits

..

2 Commits

Author SHA1 Message Date
MickLesk
42cc1d298b 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.
2026-09-17 10:49:58 +02:00
MickLesk
ad271cf58d 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.
2026-09-17 10:11:23 +02:00
4 changed files with 3 additions and 16 deletions

View File

@@ -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

View File

@@ -37,19 +37,8 @@ function update_script() {
systemctl stop suggestarr
msg_ok "Stopped Service"
mkdir -p /opt/suggestarr_data
if [[ -d /opt/suggestarr/config/config_files && ! -L /opt/suggestarr/config/config_files ]]; then
msg_info "Migrating Configuration"
cp -an /opt/suggestarr/config/config_files/. /opt/suggestarr_data/ 2>/dev/null || true
msg_ok "Migrated Configuration to /opt/suggestarr_data"
fi
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "suggestarr" "giuseppe99barchetta/SuggestArr" "tarball"
mkdir -p /opt/suggestarr/config
rm -rf /opt/suggestarr/config/config_files
ln -sfn /opt/suggestarr_data /opt/suggestarr/config/config_files
msg_info "Building Frontend"
cd /opt/suggestarr/client
$STD npm install

View File

@@ -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

View File

@@ -38,9 +38,7 @@ $STD uv pip install --python /opt/suggestarr/.venv -r /opt/suggestarr/api_servic
msg_ok "Set up Python Environment"
msg_info "Configuring SuggestArr"
mkdir -p /opt/suggestarr_data /opt/suggestarr/config
rm -rf /opt/suggestarr/config/config_files
ln -sfn /opt/suggestarr_data /opt/suggestarr/config/config_files
mkdir -p /opt/suggestarr_data
cat <<EOF >/opt/suggestarr.env
SUGGESTARR_PORT=5000
LOG_LEVEL=info