Repository navigation
feat(sql): @effect/sql-pg client, Effect Migrator and test layer - #83
Conversation
packages/db hand-rolled the Postgres client, the migration runner and a text-id ledger. A new packages/sql owns the PgClient layer from DATABASE_URL, Effect's Migrator over fromRecord (one global integer id sequence, duplicates fail, all pending steps in one transaction under ACCESS EXCLUSIVE) and a migrated-database test layer for it.layer. Today's SCHEMA_MIGRATIONS run unchanged through sql.unsafe, without the IF NOT EXISTS guards: the schema_migrations ledger is the guard now. packages/db keeps a thin migrateDatabase seam; the server, the dev runner and the vitest template migrate through it, and the driver's own runner, advisory lock and text ledger are gone.
Code review — PR 83 vs issue 72Reviewed Intent vs delivery#72 asked for a package that owns the Postgres client and Effect’s Migrator, not tables. Production That is what landed. Two places the ticket text and the PR drift:
StandardsNo hard Effect-service violations.
Soft (named whole-package imports) — import * as Sql from "@patchy/sql";The service-conventions skill prefers named imports for whole packages (e.g. Smells (all judgement)
No HTML/UI. Pre-port Spec(a) Missing / partial
(b) Scope creep
(c) Looks implemented but wrong
Verified OK
MethodThe method is right: a thin
Fragile, not wrong: I would not have invented a Sql service or moved migrations into sql early. YAGNIThis is the small model. Index is obvious; the dead runner stayed dead. export const layer = PgClient.layerConfig({ url: Config.redacted("DATABASE_URL") });
export const layerFromUrl = (url: Redacted.Redacted<string>) => PgClient.layer({ url });
export const migrate = (migrations: Migrations) =>
Migrator.make({})({ loader: Migrator.fromRecord(migrations), table: LEDGER_TABLE });Real deletions made the system smaller: hand-rolled Mild glue, not speculative: The missing Neon knob is an incomplete reservation, not a YAGNI win. TestsDone-when is covered: empty Soft spots: remigrate asserts Postgres tests that #72 allowed us to drop: pre-ledger adoption, Coverage that is gone and still useful for the interim: resume from a partly-applied Postgres ledger, and a happy-path pending step on an already-migrated database (only fail+rollback is covered). The vitest template is Migrator-built ( Docs / operators
Standards: 1 soft finding (namespace import of |
Named imports from @patchy/sql at the seam, a happy-path pending-step test and a defect check on the rollback case, the reserved Neon prepare switch acknowledged in the README, and the self-hosting, domain and dev docs brought in line with migrate-on-start and the SQL context.
|
Thanks for the review. Addressed in 68d2396: Fixed
Kept as is
Lint, typecheck and 458 tests green. |
packages/dbhand-rolls the Postgres client, the migration runner and a text-idschema_migrationsledger. The Effect port wants those on@effect/sql-pgand Effect'sMigrator, owned by a package that holds no tables, soauthandpatchescan each bring their own migrations.New
packages/sql:PgClientfromDATABASE_URL(aRedactedConfig),migrate(record)overMigrator.fromRecordcomposing per-package records into one global integer id sequence, and@patchy/sql/testing— aLayer.unwrap+acquireReleasetest layer so anit.layerblock gets a fresh migrated database dropped with the layer. Today'sSCHEMA_MIGRATIONSrun unchanged throughsql.unsafe;packages/dbkeeps only amigrateDatabasePromise seam, which the server, the dev runner and the vitest template migrate through. The driver's own runner, advisory lock and text ledger are deleted, and the language-service warnings areerrorfor the new package.Two behaviour changes from today:
schema_migrationsis now Effect's(migration_id integer, name, created_at)rather than text ids; no production database exists, so nothing is renamed or marked applied (a dev instance needspnpm dev reset).ACCESS EXCLUSIVEand a failing step rolls the whole batch back, instead of one transaction per step. Steps lost theirIF NOT EXISTSguards; the ledger is the guard.Also dropped the
pnpm db:migratescript: the server migrates on startup, before it listens.Closes #72
Built by Claude Fable 5 via Claude Code.