From aac5f5c79d705b1e9a162996c2e3537dc84e35ad Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 20 Apr 2023 13:32:54 -0700 Subject: [PATCH 1/5] add a check to check_schema_delta to account for when the schema version has been bumped locally --- scripts-dev/check_schema_delta.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 32fe7f50deea..df6d9d96d74c 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -40,10 +40,24 @@ def main(force_colors: bool) -> None: exec(r, locals) current_schema_version = locals["SCHEMA_VERSION"] - click.secho(f"Current schema version: {current_schema_version}") - 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 bumped + res = repo.git.show( + f"{repo.active_branch}:synapse/storage/schema/__init__.py" + ) + new_locals: Dict[str, Any] = {} + exec(res, new_locals) + if new_locals["SCHEMA_VERSION"] != current_schema_version: + current_schema_version = new_locals["SCHEMA_VERSION"] + + click.secho(f"Current schema version: {current_schema_version}") + seen_deltas = False bad_files = [] for diff in diffs: From f5c59dd21447221f1129a153c6531f64aeec229f Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 20 Apr 2023 13:32:59 -0700 Subject: [PATCH 2/5] newsfragment --- changelog.d/15465.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15465.bugfix diff --git a/changelog.d/15465.bugfix b/changelog.d/15465.bugfix new file mode 100644 index 000000000000..299a7f0f0eba --- /dev/null +++ b/changelog.d/15465.bugfix @@ -0,0 +1 @@ +Update the check_schema_delta script to account for when the schema version has been bumped locally. From bb21437afbbf5c7b0fe3da2e28846c511fc63e2c Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 20 Apr 2023 13:44:00 -0700 Subject: [PATCH 3/5] fix commit number --- changelog.d/{15465.bugfix => 15466.bugfix} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.d/{15465.bugfix => 15466.bugfix} (100%) diff --git a/changelog.d/15465.bugfix b/changelog.d/15466.bugfix similarity index 100% rename from changelog.d/15465.bugfix rename to changelog.d/15466.bugfix From 13dae79080759abedf7daf9f19aa2650c454b792 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 21 Apr 2023 13:20:12 -0700 Subject: [PATCH 4/5] check that the nw version is allowable before using as canonical version --- scripts-dev/check_schema_delta.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index df6d9d96d74c..67a173f915f7 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -47,14 +47,29 @@ def main(force_colors: bool) -> None: 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 bumped + # 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" ) new_locals: Dict[str, Any] = {} exec(res, new_locals) - if new_locals["SCHEMA_VERSION"] != current_schema_version: - current_schema_version = new_locals["SCHEMA_VERSION"] + + 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.secho(f"Current schema version: {current_schema_version}") From 165fec5451c9de6ba72cba6492d424c229cfcdfb Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 25 Apr 2023 10:38:46 -0700 Subject: [PATCH 5/5] read from local file to see if schema has changed --- scripts-dev/check_schema_delta.py | 47 +++++++++++++------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 67a173f915f7..fee4a8bd3d5b 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -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}")