-
-
Notifications
You must be signed in to change notification settings - Fork 625
#1885 fix: run every pending migration in version order and record it #1886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+141
−11
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c548278
#1882 fix: harden the metafile check and exempt remote sources
RAprogramm be38827
#1882 fix: validate sources and survive symlink loops
RAprogramm 2727b63
#1885 fix: run every pending migration in version order and record it
RAprogramm 5d42806
#1885 fix: close migration stdin and report pending runs honestly
RAprogramm 4fe9ecc
#1885 test: assert failed migrations retry and the installer really c…
RAprogramm 6f4ca19
Merge branch 'dev' into 1885
kRHYME7 dd84b3b
Merge remote-tracking branch 'origin/dev' into 1885
RAprogramm 8ef07b0
Merge remote-tracking branch 'fork/1885' into 1885
RAprogramm 1230a9d
#1885 fix: declare sh in the migrations the runner executes with sh
RAprogramm d51e3c7
#1885 test: fail when the migration directory yields nothing to check
RAprogramm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env bash | ||
| # Migrations have to run in version order, once each, and record what succeeded. | ||
|
|
||
| . "$(dirname -- "$0")/lib/common.sh" | ||
|
|
||
| # shellcheck source=/dev/null | ||
| if ! . "$REPO_ROOT/Scripts/global_fn.sh" 2>/dev/null; then | ||
| fail "unable to source global_fn.sh" | ||
| finish | ||
| fi | ||
|
|
||
| if ! command -v run_pending_migrations >/dev/null 2>&1 && ! type run_pending_migrations >/dev/null 2>&1; then | ||
| fail "run_pending_migrations is not defined in global_fn.sh" | ||
| finish | ||
| fi | ||
|
|
||
| work_dir=$(mktemp -d) | ||
| trap 'rm -rf "$work_dir"' EXIT | ||
|
|
||
| migration_dir="$work_dir/migrations" | ||
| state_file="$work_dir/state/applied" | ||
| order_log="$work_dir/order.log" | ||
| mkdir -p "$migration_dir" | ||
|
|
||
| for version in v25.9.1 v26.10.1; do | ||
| printf '#!/usr/bin/env sh\nprintf "%%s\\n" "%s" >>"%s"\n' "$version" "$order_log" \ | ||
| >"$migration_dir/$version.sh" | ||
| done | ||
| # Reads stdin: inheriting the runner's stdin would let it swallow the names of | ||
| # the migrations queued after it. | ||
| printf '#!/usr/bin/env sh\ncat >/dev/null\nprintf "%%s\\n" "v26.4.3" >>"%s"\n' "$order_log" \ | ||
| >"$migration_dir/v26.4.3.sh" | ||
| printf '#!/usr/bin/env sh\nexit 1\n' >"$migration_dir/v26.11.0.sh" | ||
| chmod +x "$migration_dir"/*.sh | ||
|
|
||
| run_pending_migrations "$migration_dir" "$state_file" >/dev/null 2>&1 | ||
|
|
||
| expected_order='v25.9.1 | ||
| v26.4.3 | ||
| v26.10.1' | ||
| actual_order=$(cat "$order_log" 2>/dev/null || true) | ||
| [ "$actual_order" = "$expected_order" ] || | ||
| fail "migrations ran out of version order: $(echo "$actual_order" | tr '\n' ' ')" | ||
|
|
||
| for version in v25.9.1 v26.4.3 v26.10.1; do | ||
| grep -qxF "$version.sh" "$state_file" || | ||
| fail "$version.sh succeeded but was not recorded as applied" | ||
| done | ||
|
|
||
| grep -qxF 'v26.11.0.sh' "$state_file" && | ||
| fail "a migration that exited non-zero was recorded as applied" | ||
|
|
||
| : >"$order_log" | ||
| run_pending_migrations "$migration_dir" "$state_file" >/dev/null 2>&1 | ||
|
|
||
| [ -s "$order_log" ] && | ||
| fail "already applied migrations ran a second time: $(tr '\n' ' ' <"$order_log")" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| second_pass=$(run_pending_migrations "$migration_dir" "$state_file" 2>&1 || true) | ||
| case $second_pass in | ||
| *"No outstanding migrations"*) | ||
| fail "a migration was still pending but the run reported none outstanding" | ||
| ;; | ||
| esac | ||
|
|
||
| grep -q 'run_pending_migrations' "$REPO_ROOT/Scripts/install.sh" || | ||
| fail "install.sh does not call run_pending_migrations" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| missing_dir_output=$(run_pending_migrations "$work_dir/absent" "$state_file" 2>&1) | ||
| [ -z "$missing_dir_output" ] || | ||
| fail "a missing migration directory produced output: $missing_dir_output" | ||
|
|
||
| finish | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.