Skip to main content

Module migration

Module migration 

Source
Expand description

Migration file parsing, ID computation, and chain validation.

Every migration file has a two-line header: – migration: m2<38-hex> – onto: m2<38-hex> | initial

The migration ID is m2 + 19 bytes (38 hex chars) of a SHA-256 over the body and the migration’s position in the chain (onto, plus any squashed IDs). The short ID used in filenames is the same digest cut to 6 bytes (12 hex chars). m1 — a body-only hash with a 3-byte short form — is still accepted for files already on disk; see verify_integrity.

Structs§

MigrationFile
A parsed migration file.

Enums§

MigrationError

Functions§

blank_body
Generate the stub body for a blank migration (§8.5). Includes the leading blank line that separates the header from SQL content.
chain_tip
Return the tip migration ID from an ordered chain, or "initial" if empty.
compute_id
Compute the full migration ID (§5): m2 + 38 hex chars of the digest.
compute_short_id
Compute the short migration ID used as the filename component.
parse
Parse a migration file’s content. filename is used for error messages.
parse_steps
Split a migration body on -- pylon:step markers into (transactional, sql) pairs, in order. A step is transactional unless its preceding marker was -- pylon:step non-transactional (that marker applies to the step it introduces, not the one it ends — matching the Python implementation this replaces exactly, including the leading segment before any marker always being transactional).
render_file
Build the full file content for a migration given onto and body.
split_statements
Split one step’s SQL into individual statements on top-level ;.
validate_chain
Validate that migrations form a single unbroken linear chain (§6).
verify_integrity
Re-hash a migration and verify it matches the ID in the header (§9.2).