Repository navigation
fix(migrations): the runner's filename check reads the whole listing before it answers - #389
Merged
Conversation
…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", | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_argusesgrep -Fx -- "$1" >/dev/nullinstead ofgrep -Fqx "$1". The--also makes a name that starts with-be read as a name and not as an option ofgrep: 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 -qexits 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
migrationLedger.test.ts21 passed;architecture.test.tspasses;npm run build --prefix backendclean.grep -Fqxback 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 FILEandmark FILEuse this check: the productiondb-initrunsupand 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.