DEV Community

AdmilsonCossa
AdmilsonCossa

Posted on AI-assisted

Make CI catch a SQL migration that changed after review

A reviewer approves a migration that creates users. Someone edits it to create accounts before deployment. Here’s a small way to test whether the original approval still works.

Start in an empty directory with go-migrate v1.0.1, its default SQLite configuration, and no database environment overrides. Run gomigrate init and gomigrate create add_users --seq. Replace the generated migration’s contents with this SQL.

-- +migrate Up
CREATE TABLE users (id INTEGER PRIMARY KEY);

-- +migrate Down
DROP TABLE users;
Enter fullscreen mode Exit fullscreen mode

Run gomigrate up --sql, review the statement, and copy the plan ID. Change users to accounts in the file. Now run gomigrate up --expect-plan YOUR_COPIED_ID -o json, substituting the ID you just reviewed.

The command exits with code 1 and reports plan_changed. Neither table is created. A new preview shows CREATE TABLE accounts. The same check binds the approval to the resolved database and schema, so a deployment job can catch a changed destination as well as changed SQL.

Download v1.0.1 · Approval regression tests

I used AI assistance to draft this article.

Top comments (0)