Skip to content

Database

SnapOtter uses PostgreSQL 17 with Drizzle ORM (pg-core / node-postgres) for data persistence. The schema is defined in apps/api/src/db/schema.ts.

The connection is configured via the DATABASE_URL environment variable (default postgres://snapotter:snapotter@postgres:5432/snapotter). In Docker Compose, the Postgres container stores its data in the SnapOtter-pgdata named volume.

Tables

users

Stores user accounts. Created automatically on first run from DEFAULT_USERNAME and DEFAULT_PASSWORD.

ColumnTypeNotes
iduuidPrimary key
usernamevarcharUnique, required
passwordHashvarcharscrypt hash
rolevarcharadmin, editor, or user
mustChangePasswordbooleanForced password reset flag
createdAttimestampCreation time
updatedAttimestampLast update time

sessions

Active login sessions. Each row ties a session token to a user.

ColumnTypeNotes
idvarcharPrimary key (session token)
userIduuidForeign key to users.id
expiresAttimestampExpiry time
createdAttimestampCreation time

teams

Groups for organizing users. Admins can assign users to teams.

ColumnTypeDescription
iduuidPrimary key
namevarchar (unique, max 50 chars)Team name
createdAttimestampCreation time

api_keys

API keys for programmatic access. The raw key is shown once on creation; only the hash is stored.

ColumnTypeNotes
iduuidPrimary key
userIduuidForeign key to users.id
keyHashvarcharscrypt hash of the key
namevarcharUser-provided label
createdAttimestampCreation time
lastUsedAttimestampUpdated on each authenticated request

Keys are prefixed with si_ followed by 96 hex characters (48 random bytes).

pipelines

Saved tool chains that users create in the UI.

ColumnTypeNotes
iduuidPrimary key
namevarcharPipeline name
descriptionvarcharOptional description
stepsjsonbArray of { toolId, settings } objects
createdAttimestampCreation time

user_files

Persistent file library with version chain tracking. Each processing step that saves a result creates a new row linked to its parent via parentId, forming a version tree.

ColumnTypeDescription
iduuidPrimary key
userIduuidFK to users (CASCADE DELETE)
originalNamevarcharOriginal upload filename
storedNamevarcharFilename on disk
mimeTypevarcharMIME type
sizeintegerFile size in bytes
widthintegerImage width in px
heightintegerImage height in px
versionintegerVersion number (1 = original)
parentIduuid or nullFK to user_files (parent version)
toolChainjsonbTool IDs applied in order to produce this version
createdAttimestampCreation time

jobs

Tracks processing jobs for progress reporting and cleanup.

ColumnTypeNotes
iduuidPrimary key
typevarcharTool or pipeline identifier
statusvarcharqueued, processing, completed, or failed
progressreal0.0-1.0 fraction
inputFilesjsonbArray of input file paths
outputPathvarcharPath to the result file
settingsjsonbTool settings used
errorvarcharError message if failed
createdAttimestampCreation time
completedAttimestampCompletion time

settings

Key-value store for server-wide settings that admins can change from the UI.

ColumnTypeNotes
keyvarcharPrimary key
valuevarcharSetting value
updatedAttimestampLast update time

roles

Custom roles with granular permissions.

ColumnTypeNotes
iduuidPrimary key
namevarcharUnique role name
descriptionvarcharOptional description
permissionsjsonbArray of permission strings
createdAttimestampCreation time

audit_log

Security-relevant action log.

ColumnTypeNotes
iduuidPrimary key
userIduuidFK to users
actionvarcharAction type
detailsjsonbAction-specific data
createdAttimestampAction time

Migrations

Drizzle handles schema migrations. Migration files live in apps/api/drizzle/. During development:

bash
cd apps/api
npx drizzle-kit generate   # generate a migration from schema changes
npx drizzle-kit migrate    # apply pending migrations

In production, pending migrations are applied automatically on startup.

Backup and restore

The relational database lives in the Postgres container's SnapOtter-pgdata volume, not the app's /data volume.

Option 1: pg_dump (recommended)

bash
# Dump the database while the stack is running
docker exec SnapOtter-postgres pg_dump -U snapotter snapotter > backup.sql

# Restore into a fresh database
cat backup.sql | docker exec -i SnapOtter-postgres psql -U snapotter snapotter

Option 2: Volume snapshot

bash
# Stop the stack, then snapshot the pgdata volume
docker compose down
docker run --rm -v SnapOtter-pgdata:/data -v $(pwd)/backup:/backup \
  alpine tar czf /backup/snapotter-pgdata.tar.gz -C /data .

Migrating from 1.x (SQLite)

If you are upgrading from SnapOtter 1.x, set SQLITE_MIGRATE_PATH to the path of your old snapotter.db file on first boot. The migration runs once and imports users, settings, pipelines, and files into Postgres. Remove the variable after migration succeeds.