-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CI test checking the migration names
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
#!/usr/bin/python3 | ||
# | ||
# this script ensures that all new migrations in the current branch have a | ||
# filename that is greater than all existing migrations in the release branch | ||
# | ||
|
||
|
||
RELEASE_BRANCH="origin/master" | ||
|
||
import pathlib | ||
import subprocess | ||
import sys | ||
|
||
subprocess.call(["git", "remote", "-v"]) | ||
|
||
errors = 0 | ||
for path in pathlib.Path("db-changes").glob("*"): | ||
if path.is_dir(): | ||
db = path.name | ||
print(f"{30*'#'} {db} {45*'#'}"[:79]) | ||
|
||
# get the existing migrations from the RELEASE_BRANCH | ||
proc = subprocess.run(["git", "ls-tree", f"{RELEASE_BRANCH}/develop:db-changes/{db}"], | ||
encoding="utf-8", capture_output=True, errors="replace") | ||
if proc.returncode == 0: | ||
released_migrations = set(line.split("\t", 1)[1] for line in proc.stdout.splitlines()) | ||
|
||
elif "Not a valid object name" in proc.stderr: | ||
released_migrations = [] | ||
latest_migration = "" | ||
else: | ||
sys.stderr.write(proc.stderr) | ||
proc.check_returncode() | ||
raise # not reachable | ||
|
||
latest_migration = max(released_migrations, default="") | ||
print(f"\nlatest migration in {RELEASE_BRANCH}: {latest_migration or '(none)'}\n") | ||
|
||
for migration in sorted(path.glob("*.sql")): | ||
if migration.name not in released_migrations: | ||
if migration.name > latest_migration: | ||
status = "ok" | ||
else: | ||
status = "FAIL" | ||
errors += 1 | ||
print("%-74s %4s" % (migration, status)) | ||
|
||
print() | ||
|
||
print("#"*79) | ||
if errors: | ||
print(f"{errors} errors (migrations must be ordered after all migrations in {RELEASE_BRANCH})") | ||
sys.exit(1) | ||
else: | ||
print ("success") |