Files
pangolin/server/db
Josh Voyles b7081aff11 fix: remove no-op autoFinalizeStatement wrapper and redundant busy_timeout (#2120)
better-sqlite3 11.x exposes no Statement.finalize() — the wrapper threw and
swallowed a TypeError on every query (verified: 'Statement.finalize exists:
undefined' in the runner image) while adding +122% per-statement overhead
(3.90 -> 8.66 us/op, 200k-op in-container microbench) and freeing nothing.
Statement lifecycle is GC-managed by the driver; drizzle-orm prepares fresh
per query, so nothing accumulates unbounded.

busy_timeout=5000 duplicates better-sqlite3's default timeout option, which
already arms sqlite3_busy_timeout(db, 5000) at open (lib/database.js).

With ENABLE_SQLITE_WAL_MODE unset the driver is now runtime-identical to
pre-1.18.3 (zero pragmas). The env-gated WAL block stays: journal_mode is
sticky in the DB file, so removing it would strand opted-in databases on
WAL+synchronous=FULL.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-22 15:11:51 -04:00
..
2025-12-22 16:28:41 -05:00
2025-12-09 10:56:14 -05:00
2026-01-15 17:59:45 -08:00
2026-05-02 12:09:55 -07:00
2025-10-04 18:36:44 -07:00
2026-02-12 12:13:13 -08:00
2025-12-09 10:56:14 -05:00
2026-02-24 06:31:43 +01:00
2026-02-12 12:13:13 -08:00
2025-12-22 17:44:56 +01:00

Database

Pangolin can use a Postgres or SQLite database to store its data.

Development

Postgres

To use Postgres, edit server/db/index.ts to export all from server/db/pg/index.ts:

export * from "./pg";

Make sure you have a valid config file with a connection string:

postgres:
    connection_string: postgresql://postgres:postgres@localhost:5432

You can run an ephemeral Postgres database for local development using Docker:

docker run -d \
  --name postgres \
  --rm \
  -p 5432:5432 \
  -e POSTGRES_PASSWORD=postgres \
  -v $(mktemp -d):/var/lib/postgresql/data \
  postgres:17

Schema

server/db/pg/schema.ts and server/db/sqlite/schema.ts contain the database schema definitions. These need to be kept in sync with with each other.

Stick to common data types and avoid Postgres-specific features to ensure compatibility with SQLite.

SQLite

To use SQLite, edit server/db/index.ts to export all from server/db/sqlite/index.ts:

export * from "./sqlite";

No edits to the config are needed. If you keep the Postgres config, it will be ignored.

Generate and Push Migrations

Ensure drizzle-kit is installed.

Postgres

You must have a connection string in your config file, as shown above.

npm run db:generate
npm run db:push

SQLite

npm run db:generate
npm run db:push

Build Time

There is a dockerfile for each database type. The dockerfile swaps out the server/db/index.ts file to use the correct database type.