Skip to content

TML-3693: Each database's packages move into one folder - #30829

Merged
wmadden merged 28 commits into
mainfrom
tml-3693-every-target-lives-in-one-folder-per-database
Oct 22, 2026
Merged

wmadden merged 28 commits into
mainfrom
tml-3693-every-target-lives-in-one-folder-per-database

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

This PR moves each database's packages into one folder per database. After it, everything Postgres needs is here:

packages/3-targets/postgres/
  1-target/          @internal/target-postgres
  2-adapter/         @internal/adapter-postgres
  3-driver/          @internal/driver-postgres
  4-codec-testkit/   @internal/postgres-codec-testkit
  9-facade/          @internal/postgres

Before, the same five packages were spread over four folders:

Package Was in Now in
target pack packages/3-targets/3-targets/postgres/ packages/3-targets/postgres/1-target/
adapter packages/3-targets/6-adapters/postgres/ packages/3-targets/postgres/2-adapter/
driver packages/3-targets/7-drivers/postgres/ packages/3-targets/postgres/3-driver/
codec testkit packages/3-targets/6-adapters/postgres-codec-testkit/ packages/3-targets/postgres/4-codec-testkit/
facade packages/3-extensions/postgres/ packages/3-targets/postgres/9-facade/

SQLite moves the same way. Mongo moves from packages/3-mongo-target/ and packages/3-extensions/mongo/ into packages/3-targets/mongo/. The SQL family folder packages/2-sql/ becomes packages/2-sql-family/, to match packages/2-mongo-family/.

No package is renamed. @internal/target-postgres is still @internal/target-postgres, so no import, published package or generated file changes. Only folders move.

Why we're doing this

Each database used to be spread over four folders. The target pack, adapter and driver each sat in their own role folder (3-targets/, 6-adapters/, 7-drivers/), and the facade sat in a fourth, 3-extensions/. Working on one database meant moving between all four.

The numbers 3, 6 and 7 looked like layers that the build checks, but nothing checked them. pnpm lint:deps decides what each file may import from globs in architecture.config.json, not from folders. The role folders cost something and bought nothing.

Mongo already kept its packages together, but under a top-level folder of its own, 3-mongo-target/. Copying that for every database would add a top-level folder per database.

So every database, in every family, now gets one folder under packages/3-targets/. Inside it, the numbers give the dependency order: the adapter imports the target pack, the facade imports the target pack, adapter and driver, and the driver imports none of them. Adding a database means adding one folder. MySQL and MariaDB are next, in the MySQL proof-of-concept project (projects/mysql-poc/). This PR lands first so their PRs only add files.

ADR 278 records the decision.

What changed, step by step

  1. The move. Four commits do nothing but git mv: one for the 2-sql rename, then one each for Postgres, SQLite and Mongo. git show --stat -M <commit> shows only renames.
  2. Paths. One commit updates every file that names a folder: architecture.config.json, the publish mapping in shells.ts, coverage.config.json, tsconfig.base.json, scripts, tests, fixtures, examples and READMEs. The facades and Mongo packages are one folder deeper, so their relative paths gain a ../. The publish mapping produces exactly the same published entrypoints as before.
  3. Registration. architecture.config.json must give every source file a plane: shared, control (migration) or runtime. Postgres had registered only six of its core files, so lint checked almost none of its target. Every target now registers its files the same way. Doing that showed some files filed as shared that are really control or runtime code, so they moved:
    • Control-only code went to src/core/migrations/. That covers the SQLite control target, the schema verifiers, the control mutation defaults and the Mongo control adapter.
    • Runtime-only code went to a new src/core/runtime/. That covers the SQLite runtime target, adapter and driver.
    • The Postgres constraint-name helpers moved out of migrations/. They are plain functions that shared code needs.
  4. Two new checks in pnpm lint:deps, so the layout stays honest:
    • Every source file under packages/ must match exactly one glob (scripts/lint-architecture-registration.mjs). It found 68 files that matched none, and they are now registered.
    • A package in a database folder may depend only on lower-numbered packages of the same database (scripts/lint-target-layering.mjs). This replaces the separate layering test each target had, so a new database is covered without writing a test. I checked that it fails when a forbidden import is added.
  5. Upgrade notes. The upgrade-coverage check used to require extension notes for changes under packages/3-extensions/, where the facades lived. It now also covers packages/3-targets/*/9-facade/. Two pending declarations say this PR needs no user action.
  6. Docs. The layout docs, the directory-layout rule and the onboarding recipe for adding a target are rewritten. ADR 278 is new, ADR 140 points to it, and other ADRs' paths are updated.

A gap this found, which this PR does not fix

pnpm lint:deps has never checked an import from one package to another. A workspace import such as @internal/target-sqlite resolves to the package's dist/ folder, which the config excludes, so the import disappears. Only imports between files of the same package are checked. That is true on main today.

Reading the imports by hand found seven plane violations the check should have caught. One example: the adapter's control-codecs.ts is control code that imports @internal/sql-runtime. Fixing the resolution will surface more, so it is its own issue, TML-3700. Until then, the ordering check in step 4 is what checks dependencies between one database's packages.

Effect on other open PRs

41 open PRs touch the moved folders. Git follows renames when it merges, so a PR that only edits existing files merges as before. Trial merges into six open PRs added 0 to 3 conflicts to typical ones. Most of those are files a PR adds inside a moved folder, which need accepting git's suggested new location and sometimes fixing an import. We resolve conflicts on our own PRs as they come up.

Verification

All of these pass locally:

  • pnpm build, pnpm typecheck, pnpm lint, pnpm lint:deps
  • pnpm lint:publishability, pnpm lint:docs, pnpm fixtures:check
  • pnpm test:scripts (623 tests)
  • pnpm check:upgrade-coverage --mode pr
  • the tests of every moved package
  • the one integration test that read the old folder

The full integration suite runs in the merge queue.

Alternatives considered

  • Keep the role folders. They check nothing and spread each database over four folders.
  • Copy Mongo's layout for every database, such as packages/3-postgres-target/1-postgres-target/. It adds a top-level folder per database and repeats the database's name in every folder.
  • Move only new databases, and leave Postgres, SQLite and Mongo for later. That avoids conflicts with open PRs now, but leaves two layouts side by side. The move only gets more expensive as more code lands.
  • Move single-database extension packs, such as pgvector, under their database. They use the same extension points a third-party pack would, and keeping them in 3-extensions/ shows that.

Refs: TML-3693

Agent: pangloss-22

🤖 Generated with Claude Code

wmadden-electric and others added 24 commits October 22, 2026 10:54
…base

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Matches packages/2-mongo-family. Paths are fixed in a later commit.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Target, adapter, driver, codec testkit and facade now live in one folder. Paths are fixed in a later commit.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Target, adapter, driver, codec testkit and facade now live in one folder. Paths are fixed in a later commit.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Target, adapter, driver and facade now live in one folder. Paths are fixed in a later commit.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Updates config, scripts, relative paths whose depth changed, tests, docs and
READMEs for the move. Drops tsconfig.base.json references to folders that no
longer exist. Regenerates pnpm-lock.yaml with pnpm install.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Every package under packages/3-targets/<db>/ now follows the registration
recipe: src/core/*.ts shared, src/core/migrations/** migration, exports/control.ts
migration, exports/runtime.ts runtime, exports/pack.ts shared. Each package keeps
its domain and layer. Files that had no plane get the plane their imports
require. The dead pipeline-builder glob now names query-builder.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… driver

The same check the mongo target already has.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
They describe the repository at past versions, like the release notes.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…migration plane

The control target descriptor wires the planner and runner, so it is
migration-plane code. It now lives under src/core/migrations/ like the
Mongo target's.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…migration plane

The Prisma 7 binding is shared-plane code read by the contract source
interpreter and the facade's config, and it needs the names Postgres
gives an unnamed primary key and foreign key. Those helpers are pure
naming functions, so they and the identifier cutting they use move from
src/core/migrations/ to src/core/.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The Mongo adapter now lives under packages/3-targets/, where the app
space id check forbids the raw 'app' literal.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…anges

The facades moved from packages/3-extensions/ to
packages/3-targets/<database>/9-facade/. The coverage check now treats
those three folders as extension code, so a facade change still needs an
extension declaration.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…eds no consumer change

No package name, published name or import changes.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…y folders

Only link targets and inline paths change; ADR prose is untouched.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The SQL target type-constructor test read packages/3-targets/3-targets,
which no longer exists. It now reads <db>/1-target/package.json for every
database folder and picks the SQL targets by the familyId of their pack
entry, since the Mongo target's control entry has no default export.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The extension audience listed the Postgres, SQLite and Mongo facade
folders by name, so a new database's facade would skip the declaration
requirement silently. The check now matches packages/3-targets/*/9-facade/
and diffs with a glob pathspec. A test covers a facade of a database that
does not exist yet.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
mongo-static.ts imports the Mongo target and adapter runtime entries, so
the static entry and src/static/** are runtime code, as the Postgres and
SQLite facades already register theirs.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…lder

Files directly in src/core/ are registered as shared, but some are only
used by one plane and import that plane's entry points. Move the ones
whose importers are all in that plane:

- into src/core/migrations/: the Postgres and SQLite schema verifiers,
  both adapters' control-mutation-defaults, the SQLite control driver,
  and the Mongo control adapter, control driver and inspection executor;
- into a new src/core/runtime/: the SQLite runtime target, adapter and
  driver.

Every target, adapter and driver package registers src/core/runtime/**
as runtime, beside src/core/migrations/**. Only imports change.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Replace the three per-target layering tests with one check over
packages/3-targets/<database>/. For every numbered package it reads the
production dependencies in package.json and the import specifiers in
src/, and fails when a package depends on a package of its own database
that is not numbered lower, or on any package of another database.

pnpm lint:deps runs the check, and pnpm test:scripts runs its tests,
which cover each rule with a fixture tree and run it on the repository.
A new database folder is covered without any change.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
dependency-cruiser checks a file only against the group its glob in
architecture.config.json gives it, so a file that matches no glob is never
checked and one that matches several is checked as all of them. A new
check, run first by pnpm lint:deps, fails on either. It lists files the
way dependency-cruiser does and matches globs with the same normalisation,
both now shared from scripts/architecture-globs.mjs.

The check found 68 unregistered files and 8 that matched two globs of the
same group. Register the 68 by their imports and entry point names
(framework-components ir, utils, annotations and meta-builder; ts-render;
publish-surface; the SQL and Mongo family entry points; arktype-json,
postgis, and the rest of paradedb and pgvector), and drop the redundant
ids and SQL errors globs.

Refs: TML-3693
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The layout docs listed SQL packages that no longer exist, ADR 278
claimed more than the change checks, and the recipe now has a runtime
folder and the registration and ordering checks.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner October 22, 2026 09:53
@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Warning

Review details and warnings were omitted to fit the comment limit.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30829

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30829

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30829

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30829

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30829

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30829

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30829

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30829

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30829

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30829

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30829

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30829

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30829

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30829

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30829

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30829

commit: 18f2510

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 263.54 KB (0%)
postgres / emit 231.05 KB (0%)
mongo / no-emit 219 KB (0%)
mongo / emit 182.9 KB (0%)
cf-worker / no-emit 326.54 KB (0%)
cf-worker / emit 290.34 KB (0%)

…ery-target-lives-in-one-folder-per-database

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	packages/3-targets/postgres/1-target/src/core/migrations/constraint-name-renames.ts
#	packages/3-targets/postgres/1-target/src/core/migrations/primary-key-change.ts
#	packages/3-targets/postgres/1-target/test/migrations/primary-key-change.test.ts
#	packages/3-targets/postgres/2-adapter/test/migrations/planner.primary-key-change.integration.test.ts
#	packages/3-targets/postgres/2-adapter/test/migrations/planner.referential-action-change.integration.test.ts
@wmadden
wmadden enabled auto-merge October 22, 2026 11:18
@wmadden-electric wmadden-electric changed the title TML-3693: Every database's packages live in one folder, and lint:deps checks every file and the order inside each folder TML-3693: Each database's packages move into one folder Oct 22, 2026
…ery-target-lives-in-one-folder-per-database

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	packages/3-targets/postgres/9-facade/src/exports/internal-static-context.ts
@wmadden
wmadden added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 22, 2026
… folder

The facade tarball test matched bundled sources against the old
3-extensions/postgres/ prefix, which the merge queue's integration
run caught.

Refs: TML-3693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Oct 22, 2026
@wmadden
wmadden enabled auto-merge October 22, 2026 13:28
@wmadden
wmadden added this pull request to the merge queue Oct 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 22, 2026
…ery-target-lives-in-one-folder-per-database

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	packages/1-framework/1-core/framework-components/src/shared/date-time-stored-form.ts
#	packages/1-framework/1-core/framework-components/src/shared/numeral-text.ts
#	packages/1-framework/1-core/framework-components/test/date-time-stored-form.test.ts
#	packages/1-framework/1-core/framework-components/test/numeral-text.test.ts
#	packages/2-sql-family/1-core/contract/src/date-time-stored-form.ts
#	packages/2-sql-family/1-core/contract/src/numeral-text.ts
#	packages/2-sql-family/1-core/contract/test/date-time-stored-form.test.ts
#	packages/2-sql-family/1-core/contract/test/numeral-text.test.ts
#	packages/2-sql-family/2-authoring/contract-psl/test/interpreter.discriminator-rule.test.ts
#	packages/2-sql/1-core/contract/src/date-time-stored-form.ts
#	packages/2-sql/1-core/contract/src/numeral-text.ts
#	packages/2-sql/1-core/contract/test/date-time-stored-form.test.ts
#	packages/2-sql/1-core/contract/test/numeral-text.test.ts
#	packages/3-targets/mongo/1-target/src/core/data-type-entries.ts
#	packages/3-targets/mongo/1-target/test/written-values.test.ts
@wmadden
wmadden enabled auto-merge October 22, 2026 13:48
@wmadden
wmadden added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 6af5425 Oct 22, 2026
24 checks passed
@wmadden
wmadden deleted the tml-3693-every-target-lives-in-one-folder-per-database branch October 22, 2026 14:24
Yumihariii pushed a commit to Yumihariii/orm that referenced this pull request Oct 22, 2026
…base's structure (prisma#30836)

This PR adds a MySQL target that can emit a contract and read a MySQL
database's structure. Given this contract:

```prisma
model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  role  Role
  posts Post[]
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  author   User   @relation(fields: [authorId], references: [id])
  authorId Int
}

enum Role {
  USER
  ADMIN
}
```

`prisma contract emit` now writes a contract for the target `mysql`. The
MySQL control adapter then reads a database whose tables match it
through `information_schema`. The result is the same schema description
the contract produces, so in slice 2b `db verify` can compare them. In
MySQL terms the contract means:

```sql
CREATE TABLE `User` (
  `id`    int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `email` varchar(191) NOT NULL UNIQUE,
  `role`  enum('USER','ADMIN') NOT NULL
);
```

Migrations, `db verify` and `db sign` come in the next PR. Queries come
after that.

## Why there is a MySQL target now

Prisma 8 must support MySQL and MariaDB, and APIs can still change until
8.0.0 final. The SQL family was built against Postgres and then SQLite.
This project builds a narrow MySQL target to find every place where
shared code assumes something MySQL doesn't do, while there is still
time to fix it ([`projects/mysql-poc/`](projects/mysql-poc/spec.md)).
The code is the start of real MySQL support, not a throwaway.

This is slice 2a of that project. Slice 1 (prisma#30829) moved every
database into one folder per database, so MySQL lives in
`packages/3-targets/mysql/`:

```text
packages/3-targets/mysql/
  1-target/    @internal/target-mysql    data types, codecs, PSL types, control tables
  2-adapter/   @internal/adapter-mysql   reads the database's structure, markers and ledger
  3-driver/    @internal/driver-mysql    connects through mysql2
  9-facade/    @internal/mysql           defineConfig, defineContract, the control client
```

## How MySQL represents the contract

These choices are recorded in the project's design notes.

- **A PSL enum is a native `enum('USER','ADMIN')` column.** The database
enforces membership, which is what MySQL users and Prisma 7 already
have. The target writes the members into the column's type from the
enum's value set, and refuses a contract where the two disagree. `db
verify` compares the column type with MySQL's `COLUMN_TYPE` exactly, so
renaming or reordering a member shows up as drift. No CHECK constraint
is derived.
- **`String` is `varchar(191)`.** MySQL can't put a unique index on
`text` without a key length, and 191 is what Prisma 7 uses, so databases
adopted from Prisma 7 keep their columns.
- **No namespaces yet.** Like SQLite, the target doesn't support
`namespace { }` blocks. Mapping them to MySQL databases is later work.

## What reading a MySQL database has to handle

`information_schema` reports a few things in ways the family's schema
description doesn't expect. The adapter handles each one, and each has a
test against a live server:

- InnoDB creates an index for every foreign key. The adapter drops that
index when its name and columns match the key's, or `db verify` would
report an extra index.
- MySQL reports every unique index as a unique constraint. The adapter
reports it whichever way the contract declares it.
- A literal default on a `text` column comes back escaped
(`_utf8mb4\'x\'`). The adapter reads it back to the literal.

## The driver's connection settings

The driver uses mysql2's `query()`, which sends text and escapes
parameters on the client. That makes a few connection settings matter,
so the driver fixes them on every connection:

- **It turns off `NO_BACKSLASH_ESCAPES`.** With that server setting on,
client-side escaping lets a parameter end its string early.
- **Multiple statements stay off,** even if the URL asks for them.
- **Object parameters are sent as plain strings,** not expanded into
SQL.
- **The session time zone is UTC.**

Every column comes back as the server's own text, as ADR 155 requires.

## What this found in shared code

The point of the project is to find shared code that assumes Postgres or
SQLite. This slice fixed one such assumption and recorded four new ones
in [`coupling.md`](projects/mysql-poc/coupling.md):

- **Fixed: authoring named targets to refuse namespaces.** PSL and
TypeScript authoring checked `=== 'sqlite'` and `=== 'postgres'`. They
now read the target's `supportsNamespaces` and `displayName`. Postgres
messages are unchanged, and SQLite's now use the neutral wording every
target without namespaces gets: "SQLite does not support `namespace auth
{ … }` blocks (declare models at the document top level instead)." The
reserved name `unbound` and the rule about mixing it with other
namespaces now apply to every target that supports namespaces, not only
Postgres.
- **Recorded: enum members don't reach the column-type hook.** Shared
authoring assumes a native enum is named by the column, like Postgres's
`CREATE TYPE`. MySQL's enum lists its members, and the hook never sees
them, so the target writes them itself.
- **Recorded: shared code treats a type that claims a kind as a named
enum.** It assumes a string `typeName` parameter. MySQL's enum is named
by its catalog text instead. Query parameter casts in a later slice will
hit this.
- **Recorded: the emitter writes `"postgres-schema"` into every SQL
contract's types.** MySQL avoids it for now only by not supporting
namespaces.
- **Recorded: index comparison expects Postgres's way of printing SQL.**

## Tests and CI

- Unit tests cover type mapping, enum lowering, the control-table SQL,
and the mapping of `information_schema` rows. They need no server.
- Live tests read a hand-made database and check that the family's
differ and the target's own `diffSchema` both report no differences.
They run when `MYSQL_URL` is set, and are skipped otherwise.
- The `test-packages` CI job gets a `mysql:8.4` service container, and
`docker-compose.yaml` gets one on port 3307. MariaDB's container comes
with the MariaDB slice.
- `withMysqlDatabase` in `@repo/test-utils/mysql-database` gives each
test its own database and drops it afterwards.

## Not in this PR

- Migrations, `db verify` and `db sign` come in the next slice.
- Query lowering and the runtime driver come later. Lowering refuses
with `RUNTIME.AST_UNSUPPORTED` for now.
- MySQL has no public `@prisma/*` package yet.

## Verification

All pass locally:

- `pnpm build`, `pnpm typecheck`, `pnpm lint`, `pnpm lint:deps`
- `pnpm fixtures:check`, `pnpm check:upgrade-coverage --mode pr`
- the four MySQL packages' tests against a local MySQL server
- the PSL and TypeScript authoring tests
- the SQLite target and facade tests

The local server is MySQL 9.6, so CI is the first run against 8.4.

## Alternatives considered

- **A `varchar` column with a CHECK constraint for enums.** It works,
but no MySQL user would recognise it, and a Prisma 7 database couldn't
be adopted without a change.
- **A `varchar` enum with no database enforcement, as SQLite does.** It
loses the guarantee that every value belongs to the enum.
- **Passing the members to the column-type hook.** That needs a shared
change, and only the TypeScript builder calls the hook. The namespace
factory is the one path PSL, `defineContract` and a loaded contract all
take.
- **`text` for `String`.** A unique index on it fails without a key
length.

Refs: TML-3694

Agent: pangloss-22

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Added initial MySQL support, including configuration and contract
authoring, common data types and enums, schema introspection, and a
control client.
* Added MySQL connection handling and support for reading control-table
and migration-ledger data.
* **Limitations**
* MySQL namespace blocks and migration planning or execution are not yet
supported. MySQL query AST execution is also unavailable.
* **Documentation**
* Added guidance on MySQL setup, configuration, capabilities, and
current limitations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants