Skip to Content

Upgrading Auktiva

This guide covers how to upgrade your Auktiva installation to the latest version.

Upgrading from v1.22.0 to v1.23.0? Read Upgrading to v1.23.0 first. That release has two data migrations that must run before the new code serves traffic, and the Deployment Admin updater does not run them.

Upgrading to v1.23.0

v1.23.0 changes how auction winners are notified, and it ships two migrations that change data as well as the schema. Follow the runbook for your setup in order: back up, check, migrate and deploy v1.23.0 together, then repair and verify. On Vercel with this repository’s vercel.json, the production build applies the migrations itself, right before next build.

Never deploy v1.23.0 before the migrations. The new code reads columns that only the migration adds, so every page and API route that loads auction items fails with no such column: main.auction_items.winnerNotifiedUserId, and no winner is notified. If this happens, run the migration at once. It is safe to run while v1.23.0 is live. The Vercel build in this repository migrates before it builds, so this only happens when you migrate by hand.

What changes for operators

Database migrations

  • 20261122170000_mark_past_null_dated_winners_notified marks items without their own end date as notified if their auction had already ended when the migration runs. v1.22.0 never notified the winners of such items. v1.23.0 does, and this keeps it from sending “You won” for every past auction at once. These winners are not messaged, even when the auction ended yesterday. Organizers still see them on the results page and in the export.
  • 20261122180000_add_winner_notification_record adds three nullable columns to auction_items: winnerNotifiedUserId, winnerNotifiedAmount and winnerNotifiedAt. They record who was told they won, at what amount and when. For items already marked as notified, the migration does this:
    • It records the user of the item’s latest AUCTION_WON notification with that notification’s time. If the notification was deleted, it records the current highest bidder with no time.
    • If the highest bidder changed after that message (an auction extended after it ended), the item is queued again. The new winner then gets “You won” once the item has ended. This fixes auctions that were extended before the upgrade.
    • If the winner changed but the item ended more than 14 days before the migration runs, the item is not queued again. The current highest bidder is recorded and nobody is messaged.
  • The BIDDING_REOPENED notification and e-mail types are new. SQLite and Turso store these types as text, so no column changes for them.

There are no new environment variables.

For developers: 20261122180000_add_winner_notification_record was changed before release to add the 14-day step. It was never tagged or on main. A development or QA database that applied the earlier version keeps its re-queued rows for items that ended more than 14 days ago. The notifier’s 14-day rule then records their winners without messaging anyone, so nothing needs fixing. prisma migrate dev reports that the applied migration was modified and offers to reset the database. Reset it, or recreate it from the migrations. npm run db:migrate:turso does not check for changes.

Behavior

  • Items without their own end date end with their auction everywhere: bids are refused once the auction’s end date has passed (“Bidding has ended for this item”, 400), the item page shows the ended state, and their winners get the “You won” notification and e-mail.
  • Winners are notified again when the winner changes. If an owner reopens bidding and someone else wins, the new winner is told. The previous winner is told that the win is no longer final. Items that ended more than 14 days before the notifier first sees them are recorded without a message.
  • Owners can reopen bidding from the auction settings (“Reopen bidding”), with a new end date (or none) and a choice of closed items. Bidders on reopened items get a BIDDING_REOPENED notification. A previously notified winner also gets an e-mail if they turned on item-won e-mails.
  • Editing an item can no longer reopen it once it has ended. This includes clearing an item’s own past end date (400).
  • The auction page has an organizer header with a “Close auction” dialog, and the results page totals amounts per currency and leaves out drafts.

API and export changes

The results export format changed in a way that breaks existing consumers. Update any spreadsheet or script that reads it.

  • Results export (GET /api/auctions/[id]/export, admins only):
    • Drafts are no longer included.
    • JSON: summary.totalValue is removed. summary.totalValueByCurrency lists one { currency, total, formatted, itemCount } entry per currency for won items, next to the new wonItems, leadingItems and unsoldItems counts. Each item gets a status (won, leading, unsold or open), a highestBid and an endDate. winner is now null unless the item is won.
    • CSV: the existing columns keep their names and order. “Winning Bid”, “Winning Bid Display”, “Winning Bid Normalized”, “Winner Name” and “Winner Email” are empty unless the item is won. Before, “Winning Bid” showed the current bid, or 0. New columns are appended: “Status”, “Highest Bid”, “Highest Bid Display”, “Highest Bidder Name”, “Highest Bidder Email” and “End Date”. Text cells that start with =, +, -, @, a tab or a carriage return get a leading ', so spreadsheet apps show them as text instead of running them as formulas.
  • PATCH /api/auctions/[id]: endDate must be an ISO 8601 date-time with an offset (for example 2026-12-01T18:00:00Z or 2026-12-01T19:00:00+01:00) or null. Anything else gets 422 VALIDATION_ERROR. Leave the field out to keep the current end. A later end date reopens the items that follow the auction and notifies their bidders.
  • New POST /api/auctions/[id]/reopen, owner only. The body is { "endDate": "<ISO 8601 with offset>" | null, "itemIds": ["<item-id>"] }, with at most 500 IDs. The listed items must be closed published items of this auction. It returns 200 with { auction, reopenedCount, notifiedCount }. It returns 400 when the end date is not in the future or an item cannot be reopened (with invalidItemIds), 403 for anyone but the owner, and 422 for a malformed body.
  • Clients that switch on notification types should handle the new BIDDING_REOPENED type.

Upgrade scripts

v1.23.0 ships SQL files in scripts/upgrade/v1.23.0/ and a runner for them:

FileWhenWrites
precheck.sqlBefore migrating: predicts what the upgrade doesNo
repair.sqlAfter the v1.23.0 deploy: fixes what the window leftYes
verify.sqlAfter the repair: checks the resultNo
backfill.sqlOnly if the schema was updated with prisma db pushYes

Run them from a checkout of the release:

DATABASE_URL="$DATABASE_URL" DATABASE_AUTH_TOKEN="$DATABASE_AUTH_TOKEN" \ npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/precheck.sql

The runner accepts libsql://, https:// and file: URLs, and reads .env like npm run db:migrate:turso. It runs the whole file in one transaction, so a file applies in full or not at all. Add --dry-run to see the affected row counts of repair.sql or backfill.sql without changing anything.

precheck.sql and verify.sql only read. In releases after v1.23.0 the runner runs them read-only by itself, because each file declares -- run-sql: read-only (--read-only does the same for any file). It then opens a read transaction and always rolls it back, so a read-only Turso token is enough (turso db tokens create <db-name> --read-only), and on a local SQLite file a write statement fails with SQLITE_READONLY. The runner in the v1.23.0 tag itself has no read-only mode: it runs every file in a write transaction, which a read-only token cannot open, so use a token that can write with it. The commands on this page work with both runners. repair.sql and backfill.sql always need a token that can write.

You can also run the files with turso db shell <db-name> < scripts/upgrade/v1.23.0/<file>.sql or sqlite3 <path-to-db> < scripts/upgrade/v1.23.0/<file>.sql, but then nothing keeps a file to one transaction or to reads only.

precheck.sql prints one row per outcome, and then the items whose winner changed or who will be messaged:

OutcomeWhat happens
marked_notified_follows_ended_auctionMarked as notified, nobody is messaged
notified_winner_unchangedKeeps its winner, nothing is sent
pendingLeft as is
winner_changed_requeued_endedThe new winner is told they won right after the deploy
winner_changed_requeued_openThe new winner is told once the item ends
winner_changed_recorded_over_14_daysThe new winner is recorded, nobody is messaged

notifyAfterDeploy is the number of “You won” messages v1.23.0 sends right after the deploy. recordedAfterDeploy counts items that are still pending, ended more than 14 days ago and have a highest bidder (usually none). v1.23.0 records their winner on its first run without messaging anyone. Check both numbers and the listed items before you migrate.

Runbook: Vercel and Turso

This repository’s vercel.json sets the production build command to:

prisma generate && npx tsx scripts/migrate-turso.ts && npx tsx prisma/seed-currencies.ts && next build

Git deployments are turned off (git.deploymentEnabled: false and ignoreCommand: "exit 1"). A production deployment starts only when a v* tag is pushed. The Vercel Production Deploy on Tag workflow (.github/workflows/vercel-release.yml) checks that the tag points to the head of main and calls the Vercel deploy hook, and the docs deploy hook when docs/ changed. That build runs scripts/migrate-turso.ts against the production DATABASE_URL, so it applies both migrations. It then seeds currencies, which only adds them when the table is empty and does nothing otherwise, and runs next build. Vercel switches production to the new deployment when the build succeeds.

Pushing the tag starts the deploy, and with it the migration, within seconds. Take the backup and run the pre-check before you release.

Both deploy hooks build the head of main, not the tag. A deploy hook has no commit of its own: Vercel builds whatever main points to when the hook runs. The workflow therefore refuses a tag that is not main’s head (The release tag points to <sha>, but origin/main is <sha>), so a tag can no longer deploy code it does not name. Merge nothing into main from the moment you start the release until the deployment is live. A small race remains: if main moves after the workflow’s check and before Vercel starts the build, production gets the newer main. Check the commit of the new deployment in the Vercel dashboard against git rev-list -n 1 v<version>.

  1. Back up the database before you release. Take a dump, a copy, or both:

    turso db shell <db-name> .dump > backup-<db-name>-$(date +%Y%m%d-%H%M%S).sql turso db create <db-name>-pre-v1-23 --from-db <db-name>

    Turso can also create a database from an earlier point in time with turso db create <new-db-name> --from-db <db-name> --timestamp <RFC 3339 time>, depending on your plan’s retention. Check turso db create --help for the options your CLI version supports.

  2. Run the read-only pre-check from a checkout of the head of main, which is the commit you are about to release, and review its output:

    git fetch origin && git checkout --detach origin/main npm ci DATABASE_URL="$DATABASE_URL" DATABASE_AUTH_TOKEN="$DATABASE_AUTH_TOKEN" \ npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/precheck.sql

    It changes nothing. Whether a read-only token is enough depends on the runner in that checkout; see Upgrade scripts. notifyAfterDeploy is the number of “You won” messages to expect once v1.23.0 is live.

  3. Cut the release. From a clean checkout whose HEAD is origin/main (a detached HEAD works), preview the release first, then run it:

    git fetch origin && git switch --detach origin/main npm run release -- <version> --dry-run npm run release -- <version>

    <version> is patch, minor, major or an exact X.Y.Z. The script fetches origin, refuses a dirty tree, a HEAD other than origin/main or a tag that already exists, bumps package.json and package-lock.json, commits chore: release vX.Y.Z, creates the annotated tag vX.Y.Z and pushes the commit and the tag together with git push --atomic. The tag push starts the deploy workflow, so do not merge anything into main until the deployment is live. The push goes straight to main, so main’s GitHub rules must allow it for you: a ruleset that requires pull requests or signed commits rejects it unless you can bypass it, and the atomic push then publishes neither the commit nor the tag.

    If the workflow fails at “Ensure tag is the head of main”, main moved between the release and the workflow run. Nothing was deployed and nothing was migrated. Leave the published tag as it is (do not move or delete it), make sure nothing else is about to be merged, re-run the pre-check from the new head of main if the new commits change migrations or scripts/upgrade/, and cut a new release with npm run release -- patch. Its tag then names the head of main. The workflow deploys the docs only when docs/ changed since the previous tag, and the refused tag counts as the previous one. If the refused release changed docs/, redeploy the docs yourself after the new release (Redeploy in the Vercel docs project, or its deploy hook).

    In the Vercel build log, the migration step prints Applying for each new migration and then Applied: 2 new migration(s) on a database last migrated for v1.22.0. If a build from main that included 20261122170000_mark_past_null_dated_winners_notified was already deployed, only 20261122180000_add_winner_notification_record is applied (Applied: 1). Later builds print Already applied and change nothing.

    From the migration step until the new deployment is live, v1.22.0 keeps serving production on the migrated database while next build runs. This is the window. It usually lasts as long as the build.

  4. If the build fails after the migration step, production stays on v1.22.0 with the migrated database, and the window stays open until a v1.23.0 build succeeds. Fix the cause and deploy again, for example with Redeploy on the failed deployment in the Vercel dashboard or by re-running the workflow. Re-running the workflow works only while the tag is still the head of main; otherwise it stops at “Ensure tag is the head of main”, so cut a new release with npm run release -- patch. The migration step then skips both migrations. Do not restore the database because of a failed build. Run the repair in step 5 once v1.23.0 is live; it also fixes what v1.22.0 did in the meantime.

    If the migration step itself fails, the build stops before next build and v1.22.0 keeps serving. migrate-turso.ts does not wrap a migration in a transaction. If 20261122180000_add_winner_notification_record failed partway, its columns can exist with the records not filled in, and the migration is not recorded as applied, so the next build stops with duplicate column name. In that case run scripts/upgrade/v1.23.0/backfill.sql with the runner, which repeats the data steps in one transaction. If only some of the three columns exist, first add the missing ones with the matching ALTER TABLE lines from the migration file. Then record the migration and deploy again:

    turso db shell <db-name> "INSERT INTO _prisma_migrations (id, migration_name) VALUES (lower(hex(randomblob(16))), '20261122180000_add_winner_notification_record')"

    This is the one hand edit of _prisma_migrations this runbook allows; see Rolling back for why it is safe here.

  5. Repair and verify once v1.23.0 serves all traffic:

    DATABASE_URL="$DATABASE_URL" DATABASE_AUTH_TOKEN="$DATABASE_AUTH_TOKEN" \ npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/repair.sql DATABASE_URL="$DATABASE_URL" DATABASE_AUTH_TOKEN="$DATABASE_AUTH_TOKEN" \ npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/verify.sql turso db shell <db-name> "SELECT migration_name, applied_at FROM _prisma_migrations ORDER BY applied_at DESC LIMIT 2"

    The repair is safe to run more than once. Each of its five statements reports rows affected: 0 when nothing needs fixing. Statement 5 reports how many items it queued again for their new winner.

    verify.sql prints two tables. Expect exactly this:

    TableRowColumnRight after the repairAfter the next notifier run
    1(only row)winnerRecordColumns3 (expected is 3)3
    2notified_without_recorditems00
    2notified_record_not_highest_bidderitems00
    2pending_ended_itemsitems0 or more (see below)0

    expected is 0 on every row of the second table. pending_ended_items counts ended, published items with a highest bidder whose winner the notifier has not handled yet: the items repair statement 5 just queued again, and any item that ended since the last run. The notifier runs on every GET /api/notifications, up to 50 items per run. A signed-in page sends one when it loads. After that, a visible tab polls every 5 seconds on auction pages and every 30 seconds elsewhere when realtime is off, at least every 60 seconds when realtime is configured but not connected, and not at all while realtime is connected. Load or reload a page of the app while signed in, then run verify.sql again.

    If a number differs:

    • winnerRecordColumns below 3: migration 20261122180000_add_winner_notification_record is missing or partly applied. Handle it as in step 4.
    • notified_without_record or notified_record_not_highest_bidder above 0: v1.22.0 still serves some traffic (an old deployment, an open preview, a second server), or the repair did not run against this database. Make sure only v1.23.0 runs, then run repair.sql again.
    • pending_ended_items still above 0 after a few notifier runs: look in the runtime logs for Failed to notify winner for item or Failed to process ended items. The notifier releases an item whose notification failed, so it retries it on the next run.

Vercel projects that do not migrate in the build

Use this only if your Vercel project’s build command does not run scripts/migrate-turso.ts, for example because you changed it in vercel.json or in the project settings. Then you migrate by hand, and v1.23.0 must not serve traffic before the migration:

  1. Back up and run the pre-check as in steps 1 and 2 above.

  2. Build v1.23.0 without serving it:

    vercel deploy --prod --skip-domain

    This prints the deployment URL. Do not open it before the next step, because its pages fail on the old schema. If your project deploys from Git, turn off Auto-assign Custom Production Domains in the project settings before you push the release, so the Git build is staged the same way.

  3. Migrate:

    DATABASE_URL="$DATABASE_URL" DATABASE_AUTH_TOKEN="$DATABASE_AUTH_TOKEN" \ npm run db:migrate:turso

    Expect the same Applied output as in step 3 above. Handle a partial failure as described in step 4.

  4. Promote v1.23.0 immediately:

    vercel promote <deployment-url>

    Turn Auto-assign Custom Production Domains back on afterwards if you turned it off.

  5. Repair and verify as in step 5 above.

Runbook: self-hosted

The updater runs the scripts/update.sh of the version you are on. Up to v1.23.0, that script updates the schema with prisma db push. That adds the new columns but skips the data steps of both migrations. With a Turso DATABASE_URL, prisma db push changes only the local ./dev.db fallback from prisma.config.ts and leaves Turso unchanged. Use the steps below for this upgrade. Later releases migrate instead; see Migration history and baselining.

The SQLite steps below apply the two migrations without recording them in _prisma_migrations. The first update with a later release’s updater then stops once and asks you to baseline the history, which records them.

SQLite with the Deployment Admin updater

  1. Back up the database file: cp <path-to-db> backups/backup_$(date +%Y%m%d_%H%M%S).db.

  2. Apply the two migrations before you update. On the server, in the Auktiva directory (still on v1.22.0):

    git fetch --tags origin for m in 20261122170000_mark_past_null_dated_winners_notified \ 20261122180000_add_winner_notification_record; do git show "v1.23.0:prisma/migrations/$m/migration.sql" > "/tmp/$m.sql" npx prisma db execute --file "/tmp/$m.sql" done

    prisma db execute uses the SQLite DATABASE_URL from .env. Each file prints Script executed successfully. To preview the effect first, run git show v1.23.0:scripts/upgrade/v1.23.0/precheck.sql > /tmp/precheck.sql and sqlite3 <path-to-db> < /tmp/precheck.sql if sqlite3 is installed.

  3. Install the update from Settings → Deployment Administration. Its prisma db push step finds the schema already in sync.

  4. Repair and verify after the server has restarted on v1.23.0:

    npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/repair.sql npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/verify.sql

If you already installed v1.23.0 without step 2, run the data steps now, then the repair and verify:

npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/backfill.sql

Until the backfill runs, v1.23.0 may already have told the winners of items without their own end date in auctions that ended in the last 14 days. It will not yet have told the new winners of auctions extended before the upgrade. The backfill queues those items, and the notifier then tells the new winners.

SQLite, manual upgrade

Follow Manual Upgrade and skip Step 3 (v1.22.0 and v1.23.0 do not have that check). In Step 7, apply the two migration files instead:

npm run db:generate npx prisma db execute --file prisma/migrations/20261122170000_mark_past_null_dated_winners_notified/migration.sql npx prisma db execute --file prisma/migrations/20261122180000_add_winner_notification_record/migration.sql

If the second command fails with duplicate column name: winnerNotifiedAmount, the schema was already pushed. Run scripts/upgrade/v1.23.0/backfill.sql instead. After Step 8, run the repair and verify commands above.

Turso on your own server

Do not use Install Update for this release, because it does not migrate Turso. Upgrade by hand:

git fetch --tags origin && git checkout v1.23.0 npm ci npm run db:generate npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/precheck.sql npm run db:migrate:turso npm run build pm2 restart auktiva # or: systemctl restart auktiva npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/repair.sql npx tsx scripts/upgrade/run-sql.ts scripts/upgrade/v1.23.0/verify.sql

The old process keeps serving while npm run build runs, which is the window described below.

Between the migration and the deploy

This section assumes the version you are replacing is v1.22.0. The window runs from the migration until v1.23.0 serves all traffic. With this repository’s Vercel build, that is from the build’s migration step until the new deployment goes live, so it includes all of next build, and it lasts longer if the build fails. During the window, v1.22.0 keeps running its notifier on every notification request (each signed-in page load, and the polling of open tabs), against the migrated database:

  • Items without their own end date: v1.22.0 ignores them. v1.23.0 notifies their winners after the deploy.
  • Re-queued items with their own end date that ended in the last 14 days: v1.22.0 sends the new winner the right “You won” message. It does not update the new winner record, so the record still names the previous winner. A later reopen would then tell the wrong person that their win is no longer final. repair.sql fixes this.
  • Items with their own end date that end during the window: v1.22.0 notifies their winners and leaves the record empty. repair.sql fills it in.
  • Items that ended more than 14 days before the migration: not queued again, so nobody gets a late message.
  • Owners who extend an auction during the window get the v1.22.0 behavior: no winner flag is reset. If someone then outbids the winner of an item that follows the auction, the item stays marked as notified for the previous winner. repair.sql queues it again, and v1.23.0 tells the new winner once the item has ended. If it ended more than 14 days ago, the new winner is recorded and nobody is messaged.

The upgrade itself sends nobody a second message. As in v1.22.0, two notifier runs that overlap can still both message the same winner. This applies to two v1.22.0 polls at the same moment, or a v1.22.0 and a v1.23.0 poll around the promote, because v1.22.0 does not claim items before it sends. MAINTENANCE_MODE=true does not close the window. It does not apply to /api routes, so page loads and open tabs keep requesting notifications and running the notifier. On Vercel, changing it also needs a new deployment. Keep the window short instead, for example by checking that the release commit builds before you release it, and run the repair.

Rolling back

  • Code only (Vercel Instant Rollback, vercel rollback, or checking out v1.22.0 and rebuilding): the new columns stay and v1.22.0 ignores them. v1.22.0 cannot read rows with the new BIDDING_REOPENED type, so users with such a notification would get errors loading their notifications. Remove those rows before you roll back:

    DELETE FROM "notifications" WHERE "type" = 'BIDDING_REOPENED'; DELETE FROM "email_logs" WHERE "type" = 'BIDDING_REOPENED';

    After a rollback, v1.22.0 again ignores the winners of items without their own end date. Items queued again by the migration that have their own end date notify their new winner once.

  • Data: the migrations cannot be undone in place. To return to the pre-upgrade data, restore the backup and point DATABASE_URL at it, for example the <db-name>-pre-v1-23 copy, or a new database loaded with turso db shell <new-db-name> < backup-<db-name>-<date>.sql. This loses everything written since the backup. Roll the code back with it, because v1.23.0 cannot run on the v1.22.0 schema.

  • _prisma_migrations: both migrations stay recorded unless you restore a backup taken before them. Do not edit the table by hand, with two exceptions this page documents: the INSERT in step 4 of the Vercel runbook, and baselining. Each records a migration whose changes are already in the database, after you made them yourself (step 4: the missing columns and backfill.sql) or checked them (baselining: prisma migrate diff). That is safe because scripts/migrate-turso.ts decides what to run only by the migration names in the table. Never delete a row to undo a migration: the next build would run that migration again and fail with duplicate column name, or repeat its data steps.

If you have a Deployment Admin configured, you can update directly from the Settings page:

  1. Go to Settings → Deployment Administration
  2. If an update is available, you’ll see an “Install Update” button
  3. Click the button to start the update process

The update runs scripts/update.sh of the version you are on. Since the release after v1.23.0, it:

  • Fetches the latest release
  • Checks that the database’s migration history matches its schema, and stops before changing anything if it does not (see Migration history and baselining)
  • Checks out the release and installs its dependencies
  • Backs up your database (SQLite only)
  • Applies the new migrations: prisma migrate deploy for SQLite, npm run db:migrate:turso for Turso
  • Rebuilds the application
  • Restarts the server (if PM2 is configured)

Up to v1.23.0, the script updates the schema with prisma db push and its --accept-data-loss flag instead, which skips the data steps of migrations and changes only the local ./dev.db fallback when DATABASE_URL is a Turso URL. The update from v1.23.0 or earlier to a newer release still runs that old script, because the updater always runs the installed version’s script. Read the release notes of the version you install for steps that this skips.

See Deployment Administration for details on setting up the Deployment Admin role.

Manual Upgrade

If you prefer to upgrade manually or the automatic update isn’t available, follow these steps.

Step 1: Handle Local Changes

If you installed Auktiva using the automated installer script, your working directory may have local changes (like the generated .env file). You need to stash these before pulling updates:

cd /path/to/auktiva # Check for local changes git status # Stash any local changes git stash # Fetch the latest tags git fetch --tags origin

Always stash or commit your local changes before upgrading. The update process checks out a specific release tag, which will fail if you have uncommitted changes.

Step 2: Find the Latest Release

# Get the latest release tag LATEST_TAG=$(curl -fsSL "https://api.github.com/repos/thomsa/auktiva/releases/latest" | \ grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') echo "Latest version: $LATEST_TAG"

Step 3: Check the Migration History

Still on your current version, check that the migrations can update your database:

npx tsx scripts/check-migration-history.ts

It only reads. Safe to migrate. means you can continue. Anything else means the database needs a one-time baseline first; see Migration history and baselining.

Versions up to v1.23.0 do not have this script. If the release you install has it, take it from there for this check, then remove it again so that the checkout in Step 5 is not blocked:

for f in check-migration-history.ts migration-history.ts; do git show "$LATEST_TAG:scripts/$f" > "scripts/$f" done npx tsx scripts/check-migration-history.ts rm scripts/check-migration-history.ts scripts/migration-history.ts

Step 4: Back Up Your Database

For SQLite databases, create a backup before migrating. Use the file from DATABASE_URL (.env or the environment; file:./dev.db when unset):

mkdir -p backups cp dev.db backups/backup_$(date +%Y%m%d_%H%M%S).db

For Turso databases, use Turso’s built-in backup features instead, for example turso db create <db-name>-backup --from-db <db-name>.

Step 5: Check Out the Release and Restore Your Local Changes

git checkout "$LATEST_TAG" # Restore stashed changes git stash pop

If there are conflicts (rare, but possible if configuration files changed), resolve them manually:

# If conflicts occur, check the status git status # Edit conflicting files to resolve, then: git checkout --theirs <file> # Keep the new version # or git checkout --ours <file> # Keep your version

Step 6: Install Dependencies

npm ci --include=dev

--include=dev keeps the build tools when NODE_ENV=production is set.

Step 7: Run Database Migrations

# Generate the Prisma client npm run db:generate # SQLite (DATABASE_URL starts with file:) npx prisma migrate deploy # Turso (DATABASE_URL starts with libsql:// or https://) npm run db:migrate:turso

Both apply only the migrations that _prisma_migrations does not list yet. Do not use npm run db:push on a production database: it skips the data steps of migrations and leaves the migration history behind.

Step 8: Rebuild and Restart

# Build the application npm run build # Restart your server pm2 restart auktiva # If using PM2 # or systemctl restart auktiva # If using systemd

Using the Update Script

You can also run the update script directly:

./scripts/update.sh

This script performs all the steps above automatically. However, it expects a clean working directory, so you still need to stash local changes first:

git stash ./scripts/update.sh git stash pop

It reads DATABASE_URL from the environment, else from .env, else uses file:./dev.db, and backs up to backups/ (set AUKTIVA_BACKUP_DIR to change that).

Migration history and baselining

prisma migrate deploy and npm run db:migrate:turso apply the migrations that _prisma_migrations does not list. A database whose schema was created or changed with prisma db push has tables this history does not record, and the migrations then fail: prisma migrate deploy stops with P3005 (“The database schema is not empty”) when there is no history, or with an error like table ... already exists halfway through the pending migrations when the history is behind.

That applies to:

  • installs that followed the manual installation steps (npm run db:push) or used the setup wizard before v1.1.8;
  • every install that the Deployment Admin updater of v1.23.0 or earlier updated across a schema change, because it ran prisma db push. This includes the v1.23.0 self-hosted runbook, which applies its two migrations with prisma db execute.

The setup wizard creates a SQLite database with prisma migrate deploy since v1.1.8, so its history is complete until an update pushes the schema. For a Turso database the history is the one npm run db:migrate:turso keeps; only a Turso database with tables and an empty or missing history needs a baseline.

The update script checks this before it changes anything, with scripts/check-migration-history.ts, and stops with a message like:

The database schema is ahead of its migration history. It was updated with `prisma db push` (older setups and update scripts did this), so the migrations cannot update it until its history is baselined once.

Nothing is changed and the installed version keeps running. Baseline the history once, on the version you are running, then install the update again. The script never baselines by itself.

Baseline a SQLite database

  1. Back up the database file.

  2. Check what matches. In the Auktiva directory, on the installed version:

    npx tsx scripts/check-migration-history.ts

    If the schema matches all migrations of this version, it says so and prints one npx prisma migrate resolve --applied <migration> command per migration the history is missing. It compares the schema with prisma migrate diff. You can run that comparison yourself; it prints No difference detected. on a match:

    npx prisma migrate diff --from-migrations prisma/migrations --to-config-datasource --exit-code
  3. Record the missing migrations by running the printed commands, in order. prisma migrate resolve --applied only adds the row to _prisma_migrations. It does not run the migration.

  4. Check again. npx tsx scripts/check-migration-history.ts now prints The migration history matches the database schema. Safe to migrate. Install the update again.

If the schema does not match all migrations of the installed version, do not record anything. prisma migrate diff (without --exit-code) shows the differences. Usually the database belongs to a different version than the checked-out code, for example after an update that failed halfway: check out the version the database was last updated to, or restore the backup that matches the code. Tables that Auktiva does not define also count as differences.

Recording a migration as applied skips everything in it, including data steps. The check compares the schema that prisma db push already created, but a data step (like the two in v1.23.0) only ran if you ran it yourself. Check the release notes of each version you pushed the schema to. For v1.23.0, see the self-hosted runbook and backfill.sql.

Baseline a Turso database

scripts/check-migration-history.ts cannot compare a Turso schema with the migrations, so compare a local copy:

turso db shell <db-name> .dump > turso-dump.sql DATABASE_URL="file:./turso-copy.db" npx prisma db execute --file turso-dump.sql DATABASE_URL="file:./turso-copy.db" npx tsx scripts/check-migration-history.ts

If it reports that the schema matches all migrations, record each migration it lists in the Turso database’s history, in the table and format npm run db:migrate:turso uses:

turso db shell <db-name> "CREATE TABLE IF NOT EXISTS _prisma_migrations (id TEXT PRIMARY KEY, migration_name TEXT NOT NULL UNIQUE, applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP)" turso db shell <db-name> "INSERT INTO _prisma_migrations (id, migration_name) VALUES (lower(hex(randomblob(16))), '<migration>')"

Then delete turso-dump.sql and turso-copy.db, which hold your data.

Troubleshooting

”Your local changes would be overwritten”

This error occurs when you have uncommitted changes. Stash them first:

git stash git checkout <tag> git stash pop

Merge Conflicts After Stash Pop

If git stash pop results in conflicts:

  1. Check which files have conflicts: git status
  2. For .env files, your local version is usually correct—keep it
  3. For other files, review the changes and merge manually
  4. After resolving, mark as resolved: git add <file>

The Update Stops at “Checking the database migration history”

The database needs a one-time baseline. Nothing was changed; see Migration history and baselining.

Database Migration Errors

If npx prisma migrate deploy or npm run db:migrate:turso fails:

  1. Check the error message for specific issues
  2. P3005 or already exists: the schema was pushed; see Migration history and baselining
  3. P3009 (“migrate found failed migrations”): a migration failed halfway. Restore the backup, or finish the migration by hand and record it with npx prisma migrate resolve --applied <migration> (or --rolled-back)
  4. Ensure your database is accessible
  5. For SQLite, verify the file exists and has correct permissions
  6. For Turso, check your connection credentials

If the update script fails after it checked out the release, the code is on the new tag but the running application was not rebuilt, and running the script again does nothing because it is already on that tag. The script prints the backup it took and the commit it came from. Fix the cause, then finish with Step 7 and Step 8 of the manual upgrade, or check out the previous commit, restore the backup and rebuild.

Build Failures

If npm run build fails:

  1. Clear the Next.js cache: rm -rf .next
  2. Clear node_modules and reinstall: rm -rf node_modules && npm install
  3. Check for TypeScript errors in the build output

PM2 Process Not Found

If PM2 can’t find the process:

# Check running processes pm2 list # If 'auktiva' doesn't exist, start it fresh pm2 start ecosystem.config.js pm2 save

Version Checking

To check your current version:

# From package.json node -p "require('./package.json').version" # Or check the git tag git describe --tags --exact-match 2>/dev/null || echo "Not on a release tag"

To check the latest available version:

curl -fsSL "https://api.github.com/repos/thomsa/auktiva/releases/latest" | \ grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'

Best Practices

  • Back up before upgrading — Always back up your database before major upgrades
  • Read release notes — Check the GitHub releases  for breaking changes
  • Test in staging — If possible, test upgrades in a staging environment first
  • Keep your .env safe — Your .env file contains sensitive configuration; ensure it’s preserved during upgrades
  • Stay current — Auktiva follows a rolling release model; only the latest version is supported
Last updated on