Skip to content

Export

The export script bundles everything needed to restore an Alchemify instance into a single .tar.gz archive: a full database dump, uploaded files, and a README with setup instructions.

  • PostgreSQL dba access — the script connects as dba (or the user you specify with -U)
  • An owner account — only users with the owner role can run an export
  • export-db.sh — called internally to produce the SQL dump
Terminal window
./scripts/export.sh --email owner@example.com
./scripts/export.sh --email owner@example.com -d mydb -o myexport.tar.gz

The script prompts for your password interactively (hidden input). The password never appears in shell history or the process list.

FlagDescriptionDefault
--email EMAILOwner email address (required)
-o, --output FILEOutput archive pathalchemify-export-<date>.tar.gz
-d, --database NAMEDatabase namealchemify
-U, --user NAMEPostgreSQL userdba
-H, --host HOSTPostgreSQL hostlocalhost
-p, --port PORTPostgreSQL port5432
alchemify-export/
├── README.md # Setup and restore instructions
├── sql/
│ └── dump.sql # Full database dump
└── files/
└── (uploaded files)
  • sql/dump.sql — produced by export-db.sh. Contains roles, schema, data, and a freshly generated authenticator password. Chat history and magic link tokens are excluded.
  • files/ — all files from the server’s upload directory (UPLOAD_DIR). If the directory is missing or empty, this folder will be empty.
  • README.md — generated instructions including the authenticator password and environment configuration guidance.

After extracting the archive (tar xzf alchemify-export-*.tar.gz):

Terminal window
createdb myapp
psql -v ON_ERROR_STOP=1 -U <superuser> myapp -f alchemify-export/sql/dump.sql

Create apps/server/.env using the authenticator password from the README:

DATABASE_URL=postgres://authenticator:<password>@localhost:5432/myapp
JWT_SECRET=<your-jwt-secret>
PORT=3000

Copy the contents of alchemify-export/files/ to the server’s upload directory (matching UPLOAD_DIR in your .env, default: ./uploads).

Terminal window
pnpm install
pnpm dev

The archive contains database credentials (the authenticator password). Handle it securely:

  • Don’t share it over unencrypted channels
  • Delete it after restoring if you no longer need it
  • The owner’s password is never written to the archive — it’s only used for authentication during the export process

The script resolves the upload directory in this order:

  1. $UPLOAD_DIR environment variable (if set)
  2. UPLOAD_DIR= line from apps/server/.env (if file exists)
  3. Default: ./uploads (relative to repo root)

Relative paths are resolved against the repository root.

The export scripts are selective about what goes into the archive. The goal is a clean, portable snapshot — no ephemeral tokens, no chat history.

CategoryDetails
Roles & grantsAll 7 roles (dba, authenticator, owner, admin, staff, member, anon) with correct attributes and grants. Created idempotently so restore works on a fresh database.
SchemaAll tables, indexes, triggers, functions, sequences, and RLS policies in both public and sys schemas.
Business dataEvery row in every user-created table.
User accountssys.users — all user records and role assignments.
Pagessys.pages — page layouts, navigation settings, publish status.
Files tablesys.files — file metadata records.
Metadata tablessys.table_metadata, sys.column_metadata, sys.app_metadata — all configuration the frontend and AI use.
Request logsys.request_log — query audit trail.
Uploaded filesAll files from UPLOAD_DIR, bundled in the files/ directory of the archive.
Authenticator passwordFreshly generated 48-character random hex string per export.
CategoryWhat happensWhy
sys.conversationsEntire table excluded (-T flag)Chat history is session-specific to the builder and not part of the app’s data.
sys.messagesEntire table excluded (-T flag)Same as conversations — builder chat artifacts.
public.conversations / public.messages viewsExcluded if they are views (detected dynamically)These are convenience views over the chat tables. Real business tables with these names are preserved.
sys.magic_links dataTable schema kept, rows purged (--exclude-table-data)Tokens are single-use and time-sensitive — stale tokens in an export are a security risk with no upside.

The Docker stack runs the exported app as three containers orchestrated by docker-compose.yml.

┌──────────────────────┐
│ nginx │
│ :80 │
└──┬────────────┬───────┘
│ │
/api/* │ │ /*
▼ ▼
┌──────────────┐ static files
│ Express app │ (SPA fallback)
│ :3000 │
└──────┬───────┘
┌──────────────┐
│ PostgreSQL │
│ :5432 │
└──────────────┘

nginx serves the frontend SPA and reverse-proxies API requests:

  • /api/*app:3000/* (prefix stripped)
  • /api/eventsapp:3000/events (SSE — buffering disabled, 24h timeout)
  • /assets/* → static files (1-year immutable cache)
  • /* → SPA fallback (/index.html)

Express app is the thin SQL proxy, built as a multi-stage Docker image (no source code or dev dependencies in the final image).

PostgreSQL 16 runs the init-db.sh script on first startup to apply schema.sql, sample-app.sql, and optionally chat-schema.sql.

VariableServiceDescriptionDefault
DATABASE_URLappPostgreSQL connection string (authenticator role)
JWT_SECRETappToken signing key
PORTapp / nginxApp listens on this port; nginx uses ${PORT:-80}3000 / 80
UPLOAD_DIRappFile upload directory/app/uploads
INCLUDE_CHATpostgresApply chat schema on init (true/false)true
Terminal window
docker compose up -d

On first run, PostgreSQL applies the schema via docker/init-db.sh. Subsequent starts reuse the persisted data volume.

To update an existing deployment to a newer Alchemify version:

  1. Back up the databasepg_dump before making any changes
  2. Pull the latest codegit pull
  3. Rebuild containersdocker compose build
  4. Re-apply schemapsql -U dba alchemify -f apps/server/schema.sql
  5. Restartdocker compose up -d

Always back up first. Schema changes are additive (new columns, new tables) but a backup protects against the unexpected.

After restoring an export, verify these basics:

  • Login — sign in with an existing user account
  • Query — open a table and confirm rows appear
  • File access — view or download an uploaded file
  • Permissions — confirm staff users see only what their role allows

For a non-technical overview, see the User Guide: Exporting Your App.