Skip to main content

Module d1_migrations

Module d1_migrations 

Source
Expand description

Standard-library P4b (#2608): the project’s migrations/ folder, which holds each D1 instance’s schema migrations as migrations/<database>/NNNN_<name>.sql, where <database> is the instance’s undecorated database name (d1_database_name).

The checker stays disk-free: the folder reaches it from the caller as a [bynk_project::assets::AssetFolder], and phase_d1_migrations checks the file names, reads every file of a declared database, and warns about a directory no instance owns. Wrangler applies the files and records which ran in the database itself, so nothing here tracks that.

Structs§

MigrationFile
One migration file: its name (0001_create_orders.sql) and its SQL.

Constants§

IDEMPOTENCY_BINDING
W30 (#2840): the binding of a Worker’s implicit idempotency database, which holds Idempotency.claim’s claims. A Worker that calls claim declares it with no author action; its database is <worker>-idempotency (d1_database_name), and its schema is implicit_migrations.
PG_TEST_KEY
#3321: the key the opt-in Postgres test double’s schema rides under in a D1Migrations on its way to the test emitters. Not a database name (those are <worker>-<capability>, never starting @), so it cannot collide with one, and nothing that looks a database up finds it. Present exactly when the project has [test] postgres = "pglite"; its one file is schema.sql, or none when the project has none.

Functions§

d1_database_name
P4a (#2602): the account-facing name of a D1 instance’s database, <worker>-<capability, kebab>: shop-cart and D1_ORDERS give shop-cart-orders. D1 database names are scoped to the account, as R2 bucket names are. bynk deploy environment-qualifies it.
declared_databases
Every D1 instance’s database name, from each context’s derived capabilities.
double_files
The Postgres test double’s database, as test emitters look it up: the project’s schema.sql for a Postgres instance, the migrations of a D1 database named d1_database otherwise (#3321, P4b #2608).
implicit_migrations
W30 (#2840): the migration files the compiler owns for an implicit database (the author writes no SQL), by its binding; None for any other binding. idempotency_claims holds one row per claimed key and the time it lapses; idempotency_values one per remembered key: its JSON value and the time it lapses.
is_d1
Whether instance (a context’s derived capability) is a D1 database.
is_ignored
Whether the listed key is hidden (.DS_Store, an editor’s .0001_create.sql.swp, anything under a .archive/ directory) or an editor backup (0001_create.sql~), which the folder holds without meaning to: it’s neither checked nor copied.
is_implicit_idempotency
Whether binding is a Worker’s implicit idempotency database: decided by its source, not its name, so a project’s own D1 capability named Idempotency (also bound as D1_IDEMPOTENCY) keeps its own migrations.
migration_number
The number of a well-formed migration file name, NNNN_<name>.sql: four ASCII digits, an underscore, then one or more letters, digits, _ or -. Wrangler applies a directory’s .sql files in name order, so the fixed width keeps that order numeric.
migrations_of
The migration files of database database, bound as binding: the project’s own (migrations/<database>/), or the compiler’s for an implicit database (implicit_migrations).
pglite_on
Whether the project opts in to the PGlite Postgres test double (#3321).
phase_d1_migrations
Check the listed migrations/ folder against the declared databases, and read the files of each. None means no filesystem was consulted, so there is nothing to check or read.

Type Aliases§

D1Migrations
Every declared database’s migrations, in order, keyed by database name. A database without a directory has no entry.