From 3a54189813daf5f155581fc9842de6b6780edba8 Mon Sep 17 00:00:00 2001 From: Anthony Baire Date: Thu, 4 Mar 2021 15:56:34 +0100 Subject: [PATCH] add CI test checking the migration names --- .github/workflows/maven.yml | 2 + .../database/check_migration_names.py | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 docker-compose/database/check_migration_names.py diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7770c5965c..fef82cac76 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,6 +16,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: check migration names + run: cd docker-compose/database && ./check_migration_names.py - name: Set up JDK 1.8 uses: actions/setup-java@v1 with: diff --git a/docker-compose/database/check_migration_names.py b/docker-compose/database/check_migration_names.py new file mode 100755 index 0000000000..1e6d457722 --- /dev/null +++ b/docker-compose/database/check_migration_names.py @@ -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")