Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 710502c

Browse files
authored
Update the check_schema_delta script to account for when the schema version has been bumped locally (#15466)
1 parent 8e97394 commit 710502c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

changelog.d/15466.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update the check_schema_delta script to account for when the schema version has been bumped locally.

scripts-dev/check_schema_delta.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,32 @@ def main(force_colors: bool) -> None:
4040
exec(r, locals)
4141
current_schema_version = locals["SCHEMA_VERSION"]
4242

43-
click.secho(f"Current schema version: {current_schema_version}")
44-
4543
diffs: List[git.Diff] = repo.remote().refs.develop.commit.diff(None)
4644

45+
# Get the schema version of the local file to check against current schema on develop
46+
with open("synapse/storage/schema/__init__.py", "r") as file:
47+
local_schema = file.read()
48+
new_locals: Dict[str, Any] = {}
49+
exec(local_schema, new_locals)
50+
local_schema_version = new_locals["SCHEMA_VERSION"]
51+
52+
if local_schema_version != current_schema_version:
53+
# local schema version must be +/-1 the current schema version on develop
54+
if abs(local_schema_version - current_schema_version) != 1:
55+
click.secho(
56+
"The proposed schema version has diverged more than one version from develop, please fix!",
57+
fg="red",
58+
bold=True,
59+
color=force_colors,
60+
)
61+
click.get_current_context().exit(1)
62+
63+
# right, we've changed the schema version within the allowable tolerance so
64+
# let's now use the local version as the canonical version
65+
current_schema_version = local_schema_version
66+
67+
click.secho(f"Current schema version: {current_schema_version}")
68+
4769
seen_deltas = False
4870
bad_files = []
4971
for diff in diffs:

0 commit comments

Comments
 (0)