Skip to content

fix(migrations): the runner's filename check reads the whole listing before it answers - #389

Merged
IvanJS17 merged 1 commit into
mainfrom
fix/migration-file-check-does-not-fail-by-chance
Nov 28, 2026
Merged

IvanJS17 merged 1 commit into
mainfrom
fix/migration-file-check-does-not-fail-by-chance

Conversation

@IvanJS17

@IvanJS17 IvanJS17 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

The migration runner's filename check (baseline FILE, mark FILE) no longer depends on timing: it reads the whole directory listing before it answers.

What changed

  • backend/scripts/migrate.sh: check_file_arg uses grep -Fx -- "$1" >/dev/null instead of grep -Fqx "$1". The -- also makes a name that starts with - be read as a name and not as an option of grep: such a name is now checked against the listing like any other.
  • backend/src/__tests__/migrationLedger.test.ts: a test sources the script and checks a name that sorts first in a 4,001-file directory (listing about 164 KB, well over the pipe buffer), plus a name that is not listed.
  • docs/UPSTREAM_COMPATIBILITY_LEDGER.md: a row in section 30, because the line is shared with upstream.

Why

The script runs under set -euo pipefail. grep -q exits at the first match; if the listing's writer is still writing it gets SIGPIPE, the pipeline fails, and a name that exists is reported as missing. It failed closed (nothing applied) but made unrelated CI runs fail at random.

Testing

  • Before the fix: 50 of 50 runs of the check on that directory failed; the new vitest test fails.
  • After: 0 of 50; migrationLedger.test.ts 21 passed; architecture.test.ts passes; npm run build --prefix backend clean.
  • Putting grep -Fqx back makes the test fail again (50 of 50 in the loop).

Deploy notes

No migration, no setting. The runner applies the same files in the same order. Only baseline FILE and mark FILE use this check: the production db-init runs up and never reaches it; the local Compose adoption of a volume older than the ledger (docker/db-init/adopt-ledger.sh) and the schema-drift workflow do.

…before it answers

Under pipefail a reader that stops at the first match can make the
pipeline fail while the listing is still being written, so a listed
migration could be reported as missing. The check now reads the whole
listing. A test runs it on a listing larger than a pipe buffer.
Comment on lines +261 to +274
execFileSync(
"bash",
[
"-c",
'source "$1" || exit 99; check_file_arg "$2"',
"test",
script,
name,
],
{
env: { ...process.env, MIGRATIONS_DIR: dir },
stdio: "pipe",
},
);
@IvanJS17
IvanJS17 merged commit 7827806 into main Nov 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants