This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update the check_schema_delta
script to account for when the schema version has been bumped locally
#15466
Merged
Merged
Update the check_schema_delta
script to account for when the schema version has been bumped locally
#15466
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aac5f5c
add a check to check_schema_delta to account for when the schema vers…
H-Shay f5c59dd
newsfragment
H-Shay bb21437
fix commit number
H-Shay 13dae79
check that the nw version is allowable before using as canonical version
H-Shay 165fec5
read from local file to see if schema has changed
H-Shay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update the check_schema_delta script to account for when the schema version has been bumped locally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,39 @@ 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 changed | ||
res = repo.git.show( | ||
f"{repo.active_branch}:synapse/storage/schema/__init__.py" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of looping through the diff we can just read the local file in the checkout? Which will be the merge commit? |
||
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.secho(f"Current schema version: {current_schema_version}") | ||
|
||
seen_deltas = False | ||
bad_files = [] | ||
for diff in diffs: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To summarise, we previously enforced (and continue to enforce) the invariant
but we have now altered "current schema" to mean the PR's current schema version, falling back to develop's schema version.
I think we ought to have a check which enforces that the PR's schema version is either (develop's schema version) or (develop's schema version + 1). That would prevent the following footgun: