Menu

1 / 2

Checking Database Migrations in CI: What a Pull Request Check Can Catch Without a Database

DEV Community: postgres·Son Tran·12 days ago
#bG7MuWOV
#devtopostgresql#devto#dev#migration#table
Long article (1732 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: A CI job can tell which migration statements lose data, can fail on existing rows, or rewrite and lock a table without connecting to anything, as long as it rebuilds the schema from the older migrations in the repo first. The same ALTER COLUMN email TYPE varchar(120) rewrites the table when the column was text and changes nothing on disk when it was varchar(100) , so the statement alone cannot say which. Row counts and table sizes still need a live connection.

A CI job can check a database migration without a database: rebuild the schema from the older migrations in the repo, then read each new statement against it. That is enough to say which statements drop data, which can fail on rows already in the table, which rewrite or lock it, and which add a design problem such as a foreign key with no index.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.