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 2 additions and 19 deletions

View File

@@ -79,17 +79,6 @@ function update_script() {
restore_backup
chown -R immichframe:immichframe /opt/immichframe
if ! grep -q '^Environment=IMMICHFRAME_ADMIN_PASSWORD=' /etc/systemd/system/immichframe.service; then
msg_info "Setting Admin Password"
ADMIN_PASSWORD=$(openssl rand -hex 16)
sed -i "/^Environment=DOTNET_CONTENTROOT=/a Environment=IMMICHFRAME_ADMIN_PASSWORD=${ADMIN_PASSWORD}" /etc/systemd/system/immichframe.service
{
echo "ImmichFrame Admin User: admin"
echo "ImmichFrame Admin Password: $ADMIN_PASSWORD"
} >>~/immichframe.creds
systemctl daemon-reload
msg_ok "Set Admin Password (see ~/immichframe.creds)"
fi
msg_info "Starting Service"
systemctl start immichframe

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

@@ -60,11 +60,6 @@ chown -R immichframe:immichframe /opt/immichframe
msg_ok "Setup ImmichFrame"
msg_info "Creating Service"
ADMIN_PASSWORD=$(openssl rand -hex 16)
{
echo "ImmichFrame Admin User: admin"
echo "ImmichFrame Admin Password: $ADMIN_PASSWORD"
} >>~/immichframe.creds
cat <<EOF >/etc/systemd/system/immichframe.service
[Unit]
Description=ImmichFrame Digital Photo Frame
@@ -79,7 +74,6 @@ ExecStart=/usr/bin/dotnet /opt/immichframe/ImmichFrame.WebApi.dll
Environment=ASPNETCORE_URLS=http://0.0.0.0:8080
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_CONTENTROOT=/opt/immichframe
Environment=IMMICHFRAME_ADMIN_PASSWORD=$ADMIN_PASSWORD
Restart=always
RestartSec=5
StandardOutput=journal

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