schemachange
schemachange copied to clipboard
provide way to check for changes programmatically
Is your feature request related to a problem? Please describe. We are using schemachange as part of a continuous deployment pipeline (in Azure DevOps, specifically). We want to manually review scripts that are going to be run against production, but only notify people to do so if there are any to be run.
Describe the solution you'd like I'd like a way to reliably have code determine if schemachange finds any scripts to be run. Options that come to mind are having flags for:
- JSON output
- Having the exit code indicate whether there are changes, like Terraform does
Describe alternatives you've considered Here's the solution I came up with is to parse the "Successfully applied N change scripts" line of the schemachange output.
The pipeline job
- bash: |
schemachange --config-folder config/${{ parameters.env }} -f . --dry-run | \
tee >(python3 azure/schemachange_check.py)
schemachange_check.py
import re
import sys
output = sys.stdin.read()
match = re.search(r"Successfully applied (\d+) change scripts", output)
if match:
num_changes = int(match.group(1))
has_changes = num_changes > 0
HAS_CHANGES_STR = "true" if has_changes else "false"
print(f"Changes detected: {HAS_CHANGES_STR}")
# Azure Pipeline control statements
print(
f"##vso[task.setvariable variable=HAS_CHANGES;isOutput=true]{HAS_CHANGES_STR}"
)
if has_changes:
print(
"##vso[task.logissue type=warning]👍 - Changes detected, pipeline will require a manual approval to proceed"
)
else:
print("##vso[task.logissue type=warning]ℹ️ - No changes detected")
else:
raise RuntimeError("Failed to parse the number of applied change scripts.")
Additional context none