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

Commit

Permalink
read from local file to see if schema has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Apr 25, 2023
1 parent 13dae79 commit 165fec5
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions scripts-dev/check_schema_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,27 @@ def main(force_colors: bool) -> None:

diffs: List[git.Diff] = repo.remote().refs.develop.commit.diff(None)

for diff in diffs:
if (
diff.b_path == "synapse/storage/schema/__init__.py"
and diff.change_type == "M"
):
# we've changed the schema file, let's check if the version has been changed
res = repo.git.show(
f"{repo.active_branch}:synapse/storage/schema/__init__.py"
# Get the schema version of the local file to check against current schema on develop
with open("synapse/storage/schema/__init__.py", "r") as file:
local_schema = file.read()
new_locals: Dict[str, Any] = {}
exec(local_schema, new_locals)
local_schema_version = new_locals["SCHEMA_VERSION"]

if local_schema_version != current_schema_version:
# local schema version must be +/-1 the current schema version on develop
if abs(local_schema_version - current_schema_version) != 1:
click.secho(
"The proposed schema version has diverged more than one version from develop, please fix!",
fg="red",
bold=True,
color=force_colors,
)
new_locals: Dict[str, Any] = {}
exec(res, new_locals)

local_schema_version = new_locals["SCHEMA_VERSION"]

if local_schema_version != current_schema_version:
# local schema version must be +/-1 the current schema version on develop
if abs(local_schema_version - current_schema_version) != 1:
click.secho(
"The proposed schema version has diverged more than one version from develop, please fix!",
fg="red",
bold=True,
color=force_colors,
)
click.get_current_context().exit(1)

# right, we've changed the schema version within the allowable tolerance so
# let's now use the local version as the canonical version
current_schema_version = local_schema_version
click.get_current_context().exit(1)

# right, we've changed the schema version within the allowable tolerance so
# let's now use the local version as the canonical version
current_schema_version = local_schema_version

click.secho(f"Current schema version: {current_schema_version}")

Expand Down

0 comments on commit 165fec5

Please sign in to comment.