Reylo v0.9.0
Reylo v0.9.0 types ClickHouse queries in preview, generates one TypeScript module from a project's queries, and deploys long migration histories several times faster.
Several changes can surface in an existing project, listed in Upgrading from v0.8.3.
ClickHouse, in preview
Reylo now types queries on ClickHouse 25.11 and later, in preview: its types and parameter syntax may still change (#344).
SELECT id, name, email
FROM users
WHERE id = {id:UInt64}
LIMIT 1The query runs on the official client:
import { createClient } from "@clickhouse/client";
import getUser from "./get_user.sql";
const db = createClient({ url: process.env.CLICKHOUSE_URL });
const user = await getUser.run(db, { id: 1 });
// { id: bigint; name: string; email: string | null } | nullWhat it covers:
- Connection: a
clickhouse+http://orclickhouse+https://URL to the server's HTTP interface, requiring no client for the type check - Types: inferred from ClickHouse's own
DESCRIBE, including arrays, tuples, maps and enums, and nullable only where the type isNullableorVariant - Parameters: written as ClickHouse writes them,
{id:UInt64}, or as:id::UInt64 - Cardinality: from the server's query tree, so
LIMIT 1returns at most one row and an aggregate with noGROUP BYreturns one - Clients:
@clickhouse/clientand@clickhouse/client-web - Writes:
INSERT,UPDATE,DELETEandALTER TABLE … UPDATEorDELETE, checked without running and refused when a parameterized write doesn't fit its column (#344, #447) - Not yet: Reylo Migrate, which has no migrations for ClickHouse
TypeScript codegen
The reylo generate typescript command writes every query into one TypeScript module (#437).
npx reylo generate typescript 'src/queries/**/*.sql' --out src/queries.tsEach file becomes a camelCase export named after it:
import { getUser } from "./queries.ts";
const user: getUser.Row | null = await getUser.run(db, { id: 1 });What it covers:
- Setup: runs from the
reylonpm package, with no content mapper, bundler plugin or preload on TypeScript 5.9, 7.1 or Node's type stripping - Types:
Params,RowandQueryErroron a namespace of each export's name - Errors: any error the type check would report, or two files mapping to the same export name, fails the run and writes nothing
Reylo Migrate
On Postgres and SQLite, transactional deploys now read the schema once at the end instead of after every migration (#436). From an empty Postgres 18 database on the same machine:
| Case | Before | After | Speedup |
|---|---|---|---|
| 150 one-table migrations | 8.1 s | 1.0 s | 8.1× |
| 140 migrations of a production app | 11.3 s | 1.0 s | 11.3× |
| 150 one-table migrations, 10 ms round trip | 115.7 s | 16.1 s | 7.2× |
What else changed:
- Builds before a deploy:
reylo migrate deploy --dry-run -- next buildtypes your build against a shadow of the post-deploy schema, for hosts that build before migrating (#480). - Dry runs:
reylo migrate deploy --dry-runreports what each pending migration drops or narrows. On Postgres and MySQL, it also fails if existing rows break new or validated constraints and prints a query to list them (#479). - Supabase: a project started with
reylo migrate initon Supabase now deploys to a fresh database, branch or reset stack. Previouslydeployrefused it as changed outside its migrations (#478). - Existing databases:
reylo migrate initandreylo db introspectwrite a Postgres database's default privileges and schema grants, whereinit.sqlheld only their revokes. Theinitcommand also names the roles those grants need (#431). - Moving from another tool: history tables from Prisma Migrate, Drizzle Kit, Knex, Flyway and other tools are ignored instead of written into
schema.sql(#434). - Short stamps: a migration whose name starts with a shorter stamp, as Prisma accepts, is told to pad it in place rather than prepend today's time (#433).
- Postgres indexes and keys: changed indexes and keys now build concurrently before replacing the old one, instead of dropping it a migration earlier. New primary keys,
nulls not distinctorincludeunique keys, and materialized view indexes build concurrently without--blocking. Renamed indexes rename in place (#439). - Renames and refusals: suggested commands include
--blockingwhen a migration rewrites a table, and multiple lossy column changes share one combined command. Renamed Postgres columns keep their keys, indexes, checks, views, policies and partition key in place instead of dropping and rebuilding them (#430, #439, #451, #481, #484). - Rows a deploy stops on: a deploy blocked by existing rows names the constraint, what already ran and a query for those rows instead of saying to fix the file. The
reylo migrate statuscommand reports partial multi-file changes, andmigrate()includes each refusal's detail in its error (#432). - MySQL safety: a migration's
alter tableruns in strict mode regardless ofsql_mode, failing on values its new type can't hold instead of rewriting them. Table-copying changes now require--blocking, matching Postgres (#438). - MySQL partitions and triggers: appended range or list partitions use
add partitionin place, and removed partitions drop their rows with--drop <table>.<partition>. Changed triggers now swap in one migration underlock tablesinstead of two (#438). - Identity starts: a changed
start withmoves a Postgres identity or sequence forward to the new start or past existing rows, where a migrated database kept counting from where it was (#440). - Partitioning a table: changing a Postgres table between plain and partitioned, or changing its partition key, now prints the statements to copy and restore its rows. Previously it gave a generic drop refusal (#440).
- Skipped migrations:
reylo migrate history pushrecords a database that skipped one migration and moves that migration last in the lock, where it previously refused. On Postgres, a newly created history table also revokes default-privilege grants to other roles (#441). - SQLite full-text indexes: creating or changing an external-content FTS4 or FTS5 table, or rebuilding its content table, now rebuilds the index from existing rows. Changing such an index no longer requires
--drop(#442).
Query analysis
The Postgres unique-key catalog query now reads pg_attribute through its index instead of scanning every column in the database (#446). Over two tables with four unique indexes each on Postgres 18:
| Schema size | Before | After | Speedup |
|---|---|---|---|
| 300 tables | 53 ms | 1.8 ms | 29× |
| 3,000 tables | 1,160 ms | 1.9 ms | 611× |
What else changed:
- Higher parse limits: MySQL's 500-operator cap becomes 2,000 per operator chain with no limit on wide statements. SQLite's expression depth rises from 350 to 1,000, and nested subqueries from 23 to 42 (#486).
- Depth fallback notes: Postgres and MySQL statements nested past the parse bound now note on hover and in
reylo generatethat they fell back to the server's describe (#459). - Lock timeouts: Postgres and MySQL analysis connections now time out after 10 s on a locked table instead of waiting indefinitely (#443).
Upgrading from v0.8.3
Each change below can surface in a project that upgrades from v0.8.3.
Every dialect
- Each enum value in a type descriptor is now an object,
{ "value": "active" }, where it was the string"active". Read.valuewhere code reads whatreylo analyzeprints oranalyze()returns. The types.sqlmodules get are unchanged (#420). - Migrations and
schema.sqlfiles with statements a shadow database can't replay are now refused byreylo migrate deploy,new,lockandhistory push. Previouslydeployran them andnewexecuted them on the shadow server. Move role or account changes, role grants and revokes, server settings, cross-database MySQL names and SQLiteATTACH/DETACHstatements to your server setup (#435, #487). - Running
reylo db introspectwith ashadow_urlthat can't create a shadow database now fails instead of printing the database's dump and exiting 0. Fixshadow_urlso its role can create databases, or leave it unset to fall back to the dump with a note on stderr (#482). - Running
reylo migrate deploy --dry-runon Postgres or MySQL now exits 1 when existing rows break a new or validated constraint (previously exit 0). Fix the rows listed by the dry run's query before deploying (#479). - Analysis connections on Postgres and MySQL now time out after 10 s on a locked table instead of waiting indefinitely, keeping any shorter session timeout. Re-run once the session holding the lock finishes (#443).
- Passing an Effect SQL client to
.run()now throws aTypeErrorinstead of resolving without running on SQLite. Pass the underlying driver's own client instead (#494).
Postgres
- A Supabase project started with v0.8 or earlier is refused on a database that already has
supabase_realtime, because itsinit.sqlcreates that publication. Start the migrations again with the commands the refusal prints, record them on other databases withreylo migrate history push, and move any seed rows into a new migration. Thereylo migrate initcommand also now refuses asupabase_realtimepublication declaredfor all tablesand lists the tables to publish instead (#478). - Changing an identity or sequence
start withnow requires--blockinginreylo migrate newwhen no btree index leads with its column. Moving the sequence past existing rows scans the table while blocking writes, so add an index or pass--blocking(#440).
MySQL
- A migration's
alter tablenow runs in strict mode regardless ofsql_mode, failing on values its new type can't hold instead of rewriting them. Fix those rows before deploying (#438). - Changes that copy a table while blocking writes are now refused by
reylo migrate newuntil--blockingis passed, matching Postgres. Pass--blockingfor small tables, or migrate in online steps (#438). - Removing a partition from a range or list table now drops its rows with
drop partitionand requires--drop <table>.<partition>. Previously its rows moved into another partition with no flag asked. Changing a column tocharorbinarynow also requires--drop(#438). - Running
reylo migrate initorreylo migrate newwithoutschema.sqlnow fails when no shadow database can be created, instead of writing the dump first. GrantCREATEon shadow databases or setshadow_urlin.reylo.yaml(#482).