github reylosql/reylo v0.8.3

one hour ago

Reylo v0.8.3 sets Reylo Migrate up on an existing Postgres database without pg_dump, names the next step when a deploy fails, prints rows from reylo run, and refuses SQLite inserts that leave out a required column.

A few changes can surface in an existing project, listed in Upgrading from v0.8.2.

Reylo Migrate

A migration that fails on deploy is now a refusal that names the next step (#389).

Applying to postgres://localhost:57432/pinboard_prod
  ✗ 20261122183737_handle_len_unique.sql  failed

✗ The migration 20261122183737_handle_len_unique.sql failed and was rolled back
  could not create unique index "users_handle_len" (Key (length(handle::text))=(1) is duplicated.)
  Nothing was recorded, so the next deploy runs it again.

  Fix the file, lock the fix and deploy again:
    reylo migrate dev
    reylo migrate deploy
  If another database already ran it, write a new migration instead:
    reylo migrate new <name>

What else changed:

  • Existing databases: reylo migrate init and reylo db introspect write Reylo's own SQL for a Postgres database, where they ran pg_dump and failed wherever none of the server's version was installed, and they read every schema the database uses (#390)
  • Concurrent deploys: several deploys at once no longer deadlock on a pending create index concurrently, which failed every deploy but one with deadlock detected (#386)
  • Summaries: reylo migrate new lists what the migration changes, a new table as one line with its parts under it, and each schema diff names its two sides (#383, #424)
  • After a push: reylo migrate dev says the schema is ahead of the migrations after reylo db push, where it said the two disagree (#388)
  • CI: CI=false, CI=0 and an empty CI no longer count as CI (#388)
  • Enum values: a value added to a Postgres enum is alter type … add value alone, where reylo migrate new dropped and rebuilt every view, policy and trigger on the type; a value added and used in one change is written as two migrations (#400)
  • Column defaults: a column's default, not null or identity changes without rebuilding the views, policies and triggers on it (#400)
  • Renames: a column that may be renamed is shown as a diff with a command for each answer, and a rename it wrote is one ~ line (#419)
  • Extensions: reylo migrate new writes an extension added by hand on the development database into the migration, and leaves an extension's own types and rules out of the schema (#421, #422)
  • Changes made by hand: reylo migrate history push records a change made by hand whose migration sits behind one the database hasn't run, and moves it ahead in the lock, where it found no run that makes the schema (#387)
  • The lock: each migration in reylo.lock is an object with a name and a checksum, under a version: 1 line, and a lock a newer Reylo wrote is refused with the upgrade to make (#425)

Rows from reylo run

The reylo run command now prints the rows a statement returns, up to 50 (#389).

$ reylo run 'select id, email, bio from users'
✓ select id, email, bio from users
  id  email              bio
  ──  ─────────────────  ───────────────────────
   1  ada@example.com    Wrote the first program
   2  grace@example.com  null
  Returned 2 rows

Required columns on SQLite

The type check now refuses a SQLite insert that leaves out a NOT NULL column with no default, which SQLite refuses on every row it inserts (#381).

insert into req (id, name) values (:id, :name)
--          ^^^ Column "email" of "req" is NOT NULL with no default, and this insert leaves it out,
--              so SQLite refuses every row it inserts.

It stands down where SQLite may skip the row rather than refuse it: OR IGNORE, a constraint declared ON CONFLICT IGNORE, and a BEFORE or INSTEAD OF trigger on insert.

Postgres types

Postgres now types more of what its built-in functions return (#382, #384).

select t.id, array_agg(jsonb_build_object('email', m.email)) as objects, array_agg(now()) as times
from teams t join members m on m.team_id = t.id
group by t.id

What it infers:

  • Never-null built-ins: the elements of objects and times above are non-null, where they were nullable, and so are those of array_agg over concat, gen_random_uuid() and the other built-ins that never return NULL
  • Aggregates under a user's cast: round(coalesce(sum(x), 0), 2) is non-null in a database with an implicit cast of its own, such as pgvector's, where it was nullable from v0.8.0 on

MySQL statements

The MySQL engine now reads statements with a grammar of Reylo's own, which reads more of MySQL 8.4 (#380).

table tags limit 1

What it reads:

  • TABLE statements: typed as their table, so tags above returns at most one row of non-null columns, where it returned many rows of nullable ones
  • More syntax: derived-table column aliases, several locking clauses, CAST … AT TIME ZONE, GROUP BY ROLLUP(…), JSON_VALUE … RETURNING and NATURAL INNER JOIN
  • As MySQL reads it: UPDATE IGNORE, DELETE LOW_PRIORITY, BINARY a = b, the bit literal 0b1011, and the precedence of ^ and the shifts, each of which the old reader misread

Upgrading from v0.8.2

Each change below can surface in a project that upgrades from v0.8.2.

Every dialect

  • Each migration in reylo.lock is an object with a name and a checksum, under a version: 1 line, where it was one line. A lock from v0.8.2 still reads, and the next reylo migrate dev or reylo migrate lock rewrites it. Reylo v0.8.2 refuses the new form, so upgrade every copy of Reylo that reads the lock at once (#425).

Postgres

  • An insert inside a data-modifying WITH that leaves out a required column is refused, as a plain insert already was. Write the column, or give it a default (#381).
  • An array of a ROLLUP grouping key, or of a subquery's own grouping sets, has nullable elements, where they were non-null. Handle the NULL elements where the type check now asks (#382).

SQLite

  • An insert that leaves out a NOT NULL column with no default is refused, as reylo16. Write the column, or give it a default (#381).
  • A virtual table's columns are no longer read as non-null, since SQLite checks no NOT NULL a module declares. Handle null where the type check now asks (#381).

What's Changed

  • feat(mysql): read MySQL with a grammar built on TiDB's by @colinhacks in #370
  • feat(mysql): analyze statements with reylo-sql's MySQL grammar by @colinhacks in #380
  • feat(sqlite): refuse an insert that leaves out a required column by @colinhacks in #381
  • fix(postgres): name the types of aggregates and coalesce of numbers by @colinhacks in #384
  • feat(migrate): clearer schema diffs and a summary from migrate new by @colinhacks in #383
  • fix(migrate): poll for the run lock so index builds can't deadlock it by @colinhacks in #386
  • fix(migrate): say schema.sql is ahead after a pushed enum value by @colinhacks in #388
  • fix(postgres): keep elements non-null over never-null built-ins by @colinhacks in #382
  • fix(cli): print run's rows, the page's help and deploy's next steps by @colinhacks in #389
  • fix(migrate): keep grants beside new default privileges by @colinhacks in #414
  • fix(migrate): add an enum value without rebuilding what uses it by @colinhacks in #400
  • test(lab): re-run the driver matrix for arrays of rows by @colinhacks in #415
  • fix(migrate): init and introspect without pg_dump, across schemas by @colinhacks in #390
  • test(lab): run @vercel/postgres and Knex in the driver matrix by @colinhacks in #417
  • chore(release): 0.8.3 by @colinhacks in #416
  • fix: admit infinite dates and timestamps in json schemas by @colinhacks in #418
  • fix(migrate): make an extension added by hand in the next migration by @colinhacks in #421
  • fix(migrate): leave an extension's own types and rules out of the schema by @colinhacks in #422
  • fix(migrate): raise the catalog reader's version for extension objects by @colinhacks in #423
  • feat(migrate): show a rename as a diff, and one written as a ~ line by @colinhacks in #419
  • fix(cli): reword the help and messages for migrate dev and db push by @colinhacks in #426
  • feat(migrate): write lock entries as name and checksum objects by @colinhacks in #425
  • test(cli): read the migrate help from its own docs page by @colinhacks in #427
  • feat(migrate): group a new table's parts and read routines as one line by @colinhacks in #424
  • fix(cli): move a hand change's migration ahead of undeployed ones by @colinhacks in #387

Full Changelog: v0.8.2...v0.8.3

Don't miss a new reylo release

NewReleases is sending notifications on new releases.