- Notifications
You must be signed in to change notification settings - Fork1.5k
Validate any SQL migration scripts are the most recent#6652
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes from1 commit
1ce311f2f1fe5098c28941ab6ad372aef86File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -280,6 +280,9 @@ jobs: | ||||||||||||||||
| - name: Validate migration order for pull request | ||||||||||||||||
| if: github.event_name == 'pull_request' | ||||||||||||||||
| run: | | ||||||||||||||||
| # Use C locale for consistent, locale-independent string comparison | ||||||||||||||||
| export LC_ALL=C | ||||||||||||||||
| # Get list of migrations from main branch | ||||||||||||||||
| git fetch origin main:main | ||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ❌Finding 1 continued: This fetch command should have error handling. If it fails, the script will continue with a stale or non-existent local Suggestion: if! git fetch origin main:main;thenecho"ERROR: Failed to fetch main branch"exit 1fi Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
Suggested change
| ||||||||||||||||
| MAIN_MIGRATIONS=$(git ls-tree -r --name-only main -- util/Migrator/DbScripts/*.sql | sort) | ||||||||||||||||
| @@ -312,6 +315,15 @@ jobs: | ||||||||||||||||
| while IFS= read -r migration; do | ||||||||||||||||
| MIGRATION_NAME=$(basename "$migration") | ||||||||||||||||
| # Validate migration filename format (YYYY-MM-DD_NN_Description.sql with leading zeros) | ||||||||||||||||
| if ! [[ "$MIGRATION_NAME" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}_.+\.sql$ ]]; then | ||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ❌Finding 1 - Format enforcement issue: This regex requires leading zeros (
This will cause validation failures on PRs that rebase against main if the problematic migration gets included. Options:
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ❌Critical: Regex allows non-compliant migration that breaks sorting The repository contains Problem: Lexicographic string comparison produces incorrect ordering:
Impact:
Fix required before merging: Rename the non-compliant migration: git mv util/Migrator/DbScripts/2025-10-3_00_AddOrganizationIntegration_ReadByTeamsConfigurationTenantIdTeamIdStoredProcedure.sql \ util/Migrator/DbScripts/2025-10-03_00_AddOrganizationIntegration_ReadByTeamsConfigurationTenantIdTeamIdStoredProcedure.sql Then restore strict regex validation: Suggested change
| ||||||||||||||||
| echo "ERROR: Migration '$MIGRATION_NAME' does not match expected format" | ||||||||||||||||
| echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)" | ||||||||||||||||
| echo "Example: 2025-01-15_00_MyMigration.sql" | ||||||||||||||||
| VALIDATION_FAILED=1 | ||||||||||||||||
| continue | ||||||||||||||||
| fi | ||||||||||||||||
| # Compare migration name with last main migration | ||||||||||||||||
| if [[ "$MIGRATION_NAME" < "$LAST_MAIN_MIGRATION" ]]; then | ||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 💭Finding 5 - Multiple new migrations: When a PR adds multiple migrations (e.g., The out-of-order new migrations would be caught (B would fail since it's < A alphabetically), but the error message might be confusing since it references the main branch rather than the other new migration. Is this the intended behavior, or should we also validate ordering within the set of new migrations? | ||||||||||||||||
| echo "ERROR: New migration '$MIGRATION_NAME' is not chronologically after '$LAST_MAIN_MIGRATION'" | ||||||||||||||||
| @@ -323,16 +335,16 @@ jobs: | ||||||||||||||||
| echo "" | ||||||||||||||||
| if [ $VALIDATION_FAILED -eq 1 ]; then | ||||||||||||||||
| echo "FAILED: One or more migrations are not in chronological order or incorrectly formatted" | ||||||||||||||||
| echo "" | ||||||||||||||||
| echo "Migration files must be named to execute in chronological order." | ||||||||||||||||
| echo "New migrations must have dates/names that come after existing migrations." | ||||||||||||||||
| echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)" | ||||||||||||||||
| echo "" | ||||||||||||||||
| echo "To fix this issue:" | ||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 🎨Finding 6 - Enhanced error message: Consider adding the specific git command to help developers fix the issue: echo"To fix this issue:"echo" 1. Rename using git:"echo" git mv util/Migrator/DbScripts/$MIGRATION_NAME util/Migrator/DbScripts/YYYY-MM-DD_NN_NewName.sql"echo" 2. Choose a date after$LAST_MAIN_MIGRATION"echo" 3. Commit the change: git commit -m 'Rename migration to fix ordering'" Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 🎨Enhancement: Add specific git commands to help developers fix issues: Suggested change
| ||||||||||||||||
| echo " 1. Rename your migration file(s) to use a date after $LAST_MAIN_MIGRATION" | ||||||||||||||||
| echo " 2. Ensure the date format is YYYY-MM-DD with leading zeros (e.g., 2025-01-05, not 2025-1-5)" | ||||||||||||||||
| echo " 3. Use _NN suffix(e.g., _00, _01)if multiple migrations exist for the same date" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
| @@ -342,6 +354,9 @@ jobs: | ||||||||||||||||
| - name: Validate migration order for push | ||||||||||||||||
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | ||||||||||||||||
| run: | | ||||||||||||||||
| # Use C locale for consistent, locale-independent string comparison | ||||||||||||||||
| export LC_ALL=C | ||||||||||||||||
| # Get list of migrations from previous commit | ||||||||||||||||
| PREV_MIGRATIONS=$(git ls-tree -r --name-only HEAD~1 -- util/Migrator/DbScripts/*.sql 2>/dev/null | sort || echo "") | ||||||||||||||||
| @@ -374,6 +389,15 @@ jobs: | ||||||||||||||||
| while IFS= read -r migration; do | ||||||||||||||||
| MIGRATION_NAME=$(basename "$migration") | ||||||||||||||||
| # Validate migration filename format (YYYY-MM-DD_NN_Description.sql with leading zeros) | ||||||||||||||||
| if ! [[ "$MIGRATION_NAME" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}_.+\.sql$ ]]; then | ||||||||||||||||
| echo "ERROR: Migration '$MIGRATION_NAME' does not match expected format" | ||||||||||||||||
| echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)" | ||||||||||||||||
| echo "Example: 2025-01-15_00_MyMigration.sql" | ||||||||||||||||
| VALIDATION_FAILED=1 | ||||||||||||||||
| continue | ||||||||||||||||
| fi | ||||||||||||||||
| # Compare migration name with last previous migration | ||||||||||||||||
| if [[ "$MIGRATION_NAME" < "$LAST_PREV_MIGRATION" ]]; then | ||||||||||||||||
| echo "ERROR: New migration '$MIGRATION_NAME' is not chronologically after '$LAST_PREV_MIGRATION'" | ||||||||||||||||
| @@ -385,10 +409,11 @@ jobs: | ||||||||||||||||
| echo "" | ||||||||||||||||
| if [ $VALIDATION_FAILED -eq 1 ]; then | ||||||||||||||||
| echo "FAILED: One or more migrations are not in chronological order or incorrectly formatted" | ||||||||||||||||
| echo "" | ||||||||||||||||
| echo "Migration files must be named to execute in chronological order." | ||||||||||||||||
| echo "New migrations must have dates/names that come after existing migrations." | ||||||||||||||||
| echo "Expected format: YYYY-MM-DD_NN_Description.sql (with leading zeros)" | ||||||||||||||||
| exit 1 | ||||||||||||||||
| fi | ||||||||||||||||
| else | ||||||||||||||||