Skip to content

Commit

Permalink
Switch to just one Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-d-zhang committed Aug 3, 2024
1 parent 2f4e030 commit 14ebe3f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/generate-migration-sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ jobs:
# migration file which will set globals that we can easily read
#
# see https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
git diff --name-only origin/main -- alembic/versions | xargs pdm run python -c '
# input will be newline separated paths to revision files
git diff --name-only origin/main -- alembic/versions | pdm run python -c '
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("rev", sys.argv[1])
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
print(f"{module.revision},{module.down_revision}")
' | pdm run python -c '
import sys
down_revs = set()
revs = set()
lines = (line.split(",") for line in sys.stdin)
for revision, down_revision in lines:
down_revs.add(down_revision)
revs.add(revision)
# git diff outputs an extra newline at the end
for i, path in enumerate(sys.stdin.read().rstrip().split("\n")):
spec = importlib.util.spec_from_file_location(f"rev", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
down_revs.add(module.down_revision)
revs.add(module.revision)
# the previous head revision is the down revision that does not appear
# in the list of revisions changed in this PR
head ,= down_revs - revs
print(head)
' > phr
Expand Down

0 comments on commit 14ebe3f

Please sign in to comment.