Repository navigation
Closed
Labels
Description
Problem
packages/db hand-rolls the Postgres client, the migration runner and a text-id ledger. The port replaces all three with @effect/sql-pg and Effect's Migrator, owned by a sql package that holds no tables.
Do
- New
packages/sql:PgClient.layerfrom aConfigslice (DATABASE_URLasRedacted; aprepare: falseknob reserved for the Neon pooler);Migrator.make({})fromeffect/unstable/sql(notPgMigrator.layer) withfromRecord, composing per-package migration records{ ...auth, ...patches }into one global integer id sequence — duplicates fail; the ledger is Effect'sschema_migrations(migration_id integer, name, created_at); all pending steps run in one transaction underACCESS EXCLUSIVE. Both behaviour changes from today are named in the PR. - Test layer:
Layer.unwrap+acquireRelease(createEmptyPostgresDatabase, drop)aroundPgClient.layer+ the migrator, so anit.layerblock gets a fresh, migrated database torn down with the layer. Copy frompackages/effect-slice/src/slice.test.tsandtest/postgres.tsonprototype/effect-slice. - Interim: today's six
SCHEMA_MIGRATIONS(five after reports) move underfromRecordunchanged (sql.unsafefor multi-statement strings; drop theIF NOT EXISTSidempotency — the ledger is the guard).packages/db'smigrate.tsbecomes a thinEffect.runPromiseseam over the migrator; the dev runner and vitestglobalSetupmigrate through it.packages/db's own runner andschema_migrationstext ledger are deleted. No prod database exists, so no rename or mark-applied step. - Row decoding convention documented in
packages/sql/README.md: capabilities decode rows throughSqlSchemawith aSchema.Classresult, in one module per capability;SchemaErroron a row →Effect.die;SqlErrorstays in the channel. packages/sql/CONTEXT.md(migration, ledger) and promote the language-service warnings toerrorfor the package.
Done when
Server and tests migrate through Effect's Migrator; a duplicate id fails a test; it.layer template works from an empty database; packages/db keeps only the query code the auth and patches tickets will take.
Decisions implemented
Spec §2 (SQL, Migrator), §3 (Postgres only), §7 (tests); vertical slice.
Filed from the Effect v4 port spec (#68) by the map task Write the port spec and file the build tickets.
Activity