From dc58b85da359898bdafdc178edd3dba0fb4c7d04 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:02:48 +0100 Subject: [PATCH 01/18] Check for `CREATE/DROP INDEX` in schema deltas As these should be background updates. --- scripts-dev/check_schema_delta.py | 75 ++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 467be96fdf5..5f9947fa25b 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 # Check that no schema deltas have been added to the wrong version. +# +# Also checks that schema deltas do not try and create or drop indices. import re from typing import Any, Dict, List @@ -9,6 +11,7 @@ import git SCHEMA_FILE_REGEX = re.compile(r"^synapse/storage/schema/(.*)/delta/(.*)/(.*)$") +INDEX_REGEX = re.compile(r"(CREATE|DROP) .*INDEX", flags=re.IGNORECASE) @click.command() @@ -20,6 +23,9 @@ help="Always output ANSI colours", ) def main(force_colors: bool) -> None: + # Return code. Set to non-zero when we encounter an error + return_code = 0 + click.secho( "+++ Checking schema deltas are in the right folder", fg="green", @@ -68,6 +74,7 @@ def main(force_colors: bool) -> None: seen_deltas = False bad_files = [] + all_files = [] for diff in diffs: if not diff.new_file or diff.b_path is None: continue @@ -83,6 +90,8 @@ def main(force_colors: bool) -> None: if delta_version != str(current_schema_version): bad_files.append(diff.b_path) + all_files.append(diff.b_path) + if not seen_deltas: click.secho( "No deltas found.", @@ -92,41 +101,63 @@ def main(force_colors: bool) -> None: ) return - if not bad_files: + if bad_files: + bad_files.sort() + click.secho( - f"All deltas are in the correct folder: {current_schema_version}!", - fg="green", + "Found deltas in the wrong folder!", + fg="red", bold=True, color=force_colors, ) - return - bad_files.sort() - - click.secho( - "Found deltas in the wrong folder!", - fg="red", - bold=True, - color=force_colors, - ) + for f in bad_files: + click.secho( + f"\t{f}", + fg="red", + bold=True, + color=force_colors, + ) - for f in bad_files: + click.secho() click.secho( - f"\t{f}", + f"Please move these files to delta/{current_schema_version}/", fg="red", bold=True, color=force_colors, ) - click.secho() - click.secho( - f"Please move these files to delta/{current_schema_version}/", - fg="red", - bold=True, - color=force_colors, - ) + else: + click.secho( + f"All deltas are in the correct folder: {current_schema_version}!", + fg="green", + bold=True, + color=force_colors, + ) - click.get_current_context().exit(1) + # Now check that we're not trying to create or drop indices. If we want to + # do that they should be in background updates. + for delta_file in all_files: + with open(delta_file) as fd: + delta_lines = fd.readlines() + + for line in delta_lines: + # Strip SQL comments + line, _ = line.split("--", maxsplit=1) + + match = INDEX_REGEX.search(line) + if match: + clause = match.group() + + click.secho( + f"Found delta with index creation/deletion: '{clause}' in {delta_file}\nThese should be in background updates.", + fg="red", + bold=True, + color=force_colors, + ) + return_code = 1 + + click.get_current_context().exit(return_code) if __name__ == "__main__": From 93a2e55e04a179461d0477271d855dddfcd6dc6f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:05:19 +0100 Subject: [PATCH 02/18] Newsfile --- changelog.d/18440.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/18440.misc diff --git a/changelog.d/18440.misc b/changelog.d/18440.misc new file mode 100644 index 00000000000..6aaa6dde5c9 --- /dev/null +++ b/changelog.d/18440.misc @@ -0,0 +1 @@ +Add lint to ensure we don't add a `CREATE/DROP INDEX` in a schema delta. From cd6ab9a1aabb8bba921d174854f5d389b88b65d4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:06:56 +0100 Subject: [PATCH 03/18] Test schema delta --- synapse/storage/schema/main/delta/92/05_test.sql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 synapse/storage/schema/main/delta/92/05_test.sql diff --git a/synapse/storage/schema/main/delta/92/05_test.sql b/synapse/storage/schema/main/delta/92/05_test.sql new file mode 100644 index 00000000000..3585d0d3726 --- /dev/null +++ b/synapse/storage/schema/main/delta/92/05_test.sql @@ -0,0 +1,5 @@ +-- This is a test to ensure that we don't run +-- CREATE INDEX or DROP INDEX in the schema file, and instead use +-- background updates. + +SELECT 1; From 8e7d9b0df3a0aa270f581ec001a58a0c538ee4d8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:11:56 +0100 Subject: [PATCH 04/18] fixup! Check for `CREATE/DROP INDEX` in schema deltas --- scripts-dev/check_schema_delta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 5f9947fa25b..ecefdea6d74 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -143,7 +143,7 @@ def main(force_colors: bool) -> None: for line in delta_lines: # Strip SQL comments - line, _ = line.split("--", maxsplit=1) + line = line.split("--", maxsplit=1)[0] match = INDEX_REGEX.search(line) if match: From ca36fb099c6a26e07ca8162924c36a5955f228c5 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:15:04 +0100 Subject: [PATCH 05/18] This should fail --- synapse/storage/schema/main/delta/92/05_test.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/schema/main/delta/92/05_test.sql b/synapse/storage/schema/main/delta/92/05_test.sql index 3585d0d3726..7cb5017e94f 100644 --- a/synapse/storage/schema/main/delta/92/05_test.sql +++ b/synapse/storage/schema/main/delta/92/05_test.sql @@ -2,4 +2,4 @@ -- CREATE INDEX or DROP INDEX in the schema file, and instead use -- background updates. -SELECT 1; +CREATE UNIQUE index foobar ON foobar(ads); From 3a38bd80c6884f5d6fd3bb725a9f8a0618ce624c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:17:08 +0100 Subject: [PATCH 06/18] Remove test file --- synapse/storage/schema/main/delta/92/05_test.sql | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 synapse/storage/schema/main/delta/92/05_test.sql diff --git a/synapse/storage/schema/main/delta/92/05_test.sql b/synapse/storage/schema/main/delta/92/05_test.sql deleted file mode 100644 index 7cb5017e94f..00000000000 --- a/synapse/storage/schema/main/delta/92/05_test.sql +++ /dev/null @@ -1,5 +0,0 @@ --- This is a test to ensure that we don't run --- CREATE INDEX or DROP INDEX in the schema file, and instead use --- background updates. - -CREATE UNIQUE index foobar ON foobar(ads); From 56fee66e7178b48bf7d41aa24c4581204a14e147 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:27:31 +0100 Subject: [PATCH 07/18] Better variable naming --- scripts-dev/check_schema_delta.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index ecefdea6d74..453e4081fe1 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -74,7 +74,7 @@ def main(force_colors: bool) -> None: seen_deltas = False bad_files = [] - all_files = [] + new_files = [] for diff in diffs: if not diff.new_file or diff.b_path is None: continue @@ -90,7 +90,7 @@ def main(force_colors: bool) -> None: if delta_version != str(current_schema_version): bad_files.append(diff.b_path) - all_files.append(diff.b_path) + new_files.append(diff.b_path) if not seen_deltas: click.secho( @@ -137,7 +137,7 @@ def main(force_colors: bool) -> None: # Now check that we're not trying to create or drop indices. If we want to # do that they should be in background updates. - for delta_file in all_files: + for delta_file in new_files: with open(delta_file) as fd: delta_lines = fd.readlines() From 5df4d3ff3383073378b06adf63c62c9eb695370a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:33:52 +0100 Subject: [PATCH 08/18] Check for index creation across all changed deltas, not just new ones --- scripts-dev/check_schema_delta.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 453e4081fe1..7f03c694f08 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -74,8 +74,10 @@ def main(force_colors: bool) -> None: seen_deltas = False bad_files = [] - new_files = [] + changed_files = [] for diff in diffs: + changed_files.append(diff.b_path) + if not diff.new_file or diff.b_path is None: continue @@ -90,8 +92,6 @@ def main(force_colors: bool) -> None: if delta_version != str(current_schema_version): bad_files.append(diff.b_path) - new_files.append(diff.b_path) - if not seen_deltas: click.secho( "No deltas found.", @@ -137,7 +137,7 @@ def main(force_colors: bool) -> None: # Now check that we're not trying to create or drop indices. If we want to # do that they should be in background updates. - for delta_file in new_files: + for delta_file in changed_files: with open(delta_file) as fd: delta_lines = fd.readlines() From 649a9c6e48d0159d3748f85b050281e0019c2954 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 14 May 2025 16:36:32 +0100 Subject: [PATCH 09/18] Review --- scripts-dev/check_schema_delta.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 7f03c694f08..ab67fb124b9 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -73,24 +73,24 @@ def main(force_colors: bool) -> None: click.secho(f"Current schema version: {current_schema_version}") seen_deltas = False - bad_files = [] - changed_files = [] + bad_delta_files = [] + changed_delta_files = [] for diff in diffs: - changed_files.append(diff.b_path) - - if not diff.new_file or diff.b_path is None: - continue - match = SCHEMA_FILE_REGEX.match(diff.b_path) if not match: continue + changed_delta_files.append(diff.b_path) + + if not diff.new_file or diff.b_path is None: + continue + seen_deltas = True _, delta_version, _ = match.groups() if delta_version != str(current_schema_version): - bad_files.append(diff.b_path) + bad_delta_files.append(diff.b_path) if not seen_deltas: click.secho( @@ -101,8 +101,8 @@ def main(force_colors: bool) -> None: ) return - if bad_files: - bad_files.sort() + if bad_delta_files: + bad_delta_files.sort() click.secho( "Found deltas in the wrong folder!", @@ -111,7 +111,7 @@ def main(force_colors: bool) -> None: color=force_colors, ) - for f in bad_files: + for f in bad_delta_files: click.secho( f"\t{f}", fg="red", @@ -137,7 +137,7 @@ def main(force_colors: bool) -> None: # Now check that we're not trying to create or drop indices. If we want to # do that they should be in background updates. - for delta_file in changed_files: + for delta_file in changed_delta_files: with open(delta_file) as fd: delta_lines = fd.readlines() From 1a7a9824b971596d3fecb2a13e6e9422aebb9c59 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 13:56:17 +0100 Subject: [PATCH 10/18] Allow creating indices on new tables --- scripts-dev/check_schema_delta.py | 47 +++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index ab67fb124b9..0b70ff7ab5b 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -11,7 +11,11 @@ import git SCHEMA_FILE_REGEX = re.compile(r"^synapse/storage/schema/(.*)/delta/(.*)/(.*)$") -INDEX_REGEX = re.compile(r"(CREATE|DROP) .*INDEX", flags=re.IGNORECASE) +INDEX_CREATION_REGEX = re.compile( + r"(CREATE .*INDEX .*ON ([a-z_]+)", flags=re.IGNORECASE +) +INDEX_DELETION_REGEX = re.compile(r"DROP .*INDEX ([a-z_]+)", flags=re.IGNORECASE) +TABLE_CREATION_REGEX = re.compile(r"(CREATE .*TABLE ([a-z_]+)", flags=re.IGNORECASE) @click.command() @@ -76,13 +80,17 @@ def main(force_colors: bool) -> None: bad_delta_files = [] changed_delta_files = [] for diff in diffs: + if diff.b_path is None: + # We don't lint deleted files. + continue + match = SCHEMA_FILE_REGEX.match(diff.b_path) if not match: continue changed_delta_files.append(diff.b_path) - if not diff.new_file or diff.b_path is None: + if not diff.new_file: continue seen_deltas = True @@ -136,27 +144,56 @@ def main(force_colors: bool) -> None: ) # Now check that we're not trying to create or drop indices. If we want to - # do that they should be in background updates. + # do that they should be in background updates. The exception is when we + # create indices on tables we've just created. for delta_file in changed_delta_files: with open(delta_file) as fd: delta_lines = fd.readlines() + # Strip SQL comments + delta_lines = [line.split("--", maxsplit=1)[0] for line in delta_lines] + + # First find all tables we create in this delta file. + + # Now check for index creation/deletion + created_tables = set() for line in delta_lines: # Strip SQL comments line = line.split("--", maxsplit=1)[0] - match = INDEX_REGEX.search(line) + # Check and track any tables we create + match = TABLE_CREATION_REGEX.search(line) + if match: + table_name = match.group(1) + created_tables.add(table_name) + + # Check for dropping indices, these are always banned + match = INDEX_DELETION_REGEX.search(line) if match: clause = match.group() click.secho( - f"Found delta with index creation/deletion: '{clause}' in {delta_file}\nThese should be in background updates.", + f"Found delta with index deletion: '{clause}' in {delta_file}\nThese should be in background updates.", fg="red", bold=True, color=force_colors, ) return_code = 1 + # Check for index creation, which is only allowed for tables we've + # created. + match = INDEX_CREATION_REGEX.search(line) + if match: + table_name = match.group(1) + if table_name not in created_tables: + click.secho( + f"Found delta with index creation: '{clause}' in {delta_file}\nThese should be in background updates.", + fg="red", + bold=True, + color=force_colors, + ) + return_code = 1 + click.get_current_context().exit(return_code) From 02472c2c0ddda2304f6c88bf8f620f03b4e3182d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 13:57:17 +0100 Subject: [PATCH 11/18] Test --- synapse/storage/schema/main/delta/92/05_test.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 synapse/storage/schema/main/delta/92/05_test.sql diff --git a/synapse/storage/schema/main/delta/92/05_test.sql b/synapse/storage/schema/main/delta/92/05_test.sql new file mode 100644 index 00000000000..f9e033957e2 --- /dev/null +++ b/synapse/storage/schema/main/delta/92/05_test.sql @@ -0,0 +1,11 @@ + + +-- This is a test + +CREATE TABLE test_table( + foo TEXT NOT NULL +); + +CREATE index asdasd on test_table(foo); + +CREATE INDEX test ON some_other_table(asdasd); From c291d433621e4831a90a1190602001474933ef4e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 14:01:10 +0100 Subject: [PATCH 12/18] Fixup --- scripts-dev/check_schema_delta.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 0b70ff7ab5b..f752b04c5f5 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -11,11 +11,9 @@ import git SCHEMA_FILE_REGEX = re.compile(r"^synapse/storage/schema/(.*)/delta/(.*)/(.*)$") -INDEX_CREATION_REGEX = re.compile( - r"(CREATE .*INDEX .*ON ([a-z_]+)", flags=re.IGNORECASE -) +INDEX_CREATION_REGEX = re.compile(r"CREATE .*INDEX .*ON ([a-z_]+)", flags=re.IGNORECASE) INDEX_DELETION_REGEX = re.compile(r"DROP .*INDEX ([a-z_]+)", flags=re.IGNORECASE) -TABLE_CREATION_REGEX = re.compile(r"(CREATE .*TABLE ([a-z_]+)", flags=re.IGNORECASE) +TABLE_CREATION_REGEX = re.compile(r"CREATE .*TABLE ([a-z_]+)", flags=re.IGNORECASE) @click.command() @@ -184,6 +182,7 @@ def main(force_colors: bool) -> None: # created. match = INDEX_CREATION_REGEX.search(line) if match: + clause = match.group() table_name = match.group(1) if table_name not in created_tables: click.secho( From 2c67b5f81d2754352acdf9fcc289c5e220f50b48 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 14:01:46 +0100 Subject: [PATCH 13/18] Remove test file --- synapse/storage/schema/main/delta/92/05_test.sql | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 synapse/storage/schema/main/delta/92/05_test.sql diff --git a/synapse/storage/schema/main/delta/92/05_test.sql b/synapse/storage/schema/main/delta/92/05_test.sql deleted file mode 100644 index f9e033957e2..00000000000 --- a/synapse/storage/schema/main/delta/92/05_test.sql +++ /dev/null @@ -1,11 +0,0 @@ - - --- This is a test - -CREATE TABLE test_table( - foo TEXT NOT NULL -); - -CREATE index asdasd on test_table(foo); - -CREATE INDEX test ON some_other_table(asdasd); From 0b4874a313022ccff1004e44821b1ab66169e39a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 14:08:31 +0100 Subject: [PATCH 14/18] Only fetch develop --- scripts-dev/check_schema_delta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index f752b04c5f5..e7a96fcfbdc 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -38,7 +38,7 @@ def main(force_colors: bool) -> None: click.secho("Updating repo...") repo = git.Repo() - repo.remote().fetch() + repo.remote().fetch(refspec="develop") click.secho("Getting current schema version...") From ea2d8b7416a8d1ffc842ef6473023a45294dc61d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 15 May 2025 14:11:19 +0100 Subject: [PATCH 15/18] Allow table and index creation to be in different delta files --- scripts-dev/check_schema_delta.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index e7a96fcfbdc..49f01bfc7be 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -141,9 +141,13 @@ def main(force_colors: bool) -> None: color=force_colors, ) + # Make sure we process them in order. + changed_delta_files.sort() + # Now check that we're not trying to create or drop indices. If we want to # do that they should be in background updates. The exception is when we # create indices on tables we've just created. + created_tables = set() for delta_file in changed_delta_files: with open(delta_file) as fd: delta_lines = fd.readlines() @@ -151,10 +155,6 @@ def main(force_colors: bool) -> None: # Strip SQL comments delta_lines = [line.split("--", maxsplit=1)[0] for line in delta_lines] - # First find all tables we create in this delta file. - - # Now check for index creation/deletion - created_tables = set() for line in delta_lines: # Strip SQL comments line = line.split("--", maxsplit=1)[0] From 430fe29838faf3e8e6a2aa1d3251a82b424144b2 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 19 May 2025 11:38:04 +0100 Subject: [PATCH 16/18] Update scripts-dev/check_schema_delta.py Co-authored-by: Eric Eastwood --- scripts-dev/check_schema_delta.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 49f01bfc7be..e2602c2c31b 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -141,7 +141,8 @@ def main(force_colors: bool) -> None: color=force_colors, ) - # Make sure we process them in order. + # Make sure we process them in order. This sort works because deltas are numbered + # and delta files are also numbered in order. changed_delta_files.sort() # Now check that we're not trying to create or drop indices. If we want to From 0bff73837533f651740b9df055075e02c2c4e44d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 19 May 2025 11:38:30 +0100 Subject: [PATCH 17/18] Only strip SQL comments once --- scripts-dev/check_schema_delta.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index e2602c2c31b..daf72e0531d 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -153,9 +153,6 @@ def main(force_colors: bool) -> None: with open(delta_file) as fd: delta_lines = fd.readlines() - # Strip SQL comments - delta_lines = [line.split("--", maxsplit=1)[0] for line in delta_lines] - for line in delta_lines: # Strip SQL comments line = line.split("--", maxsplit=1)[0] From 983c4dc1fa87153e623240972b042e09577c57cf Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 19 May 2025 11:41:19 +0100 Subject: [PATCH 18/18] Review comments --- scripts-dev/check_schema_delta.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index daf72e0531d..454784c3ae9 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -15,6 +15,10 @@ INDEX_DELETION_REGEX = re.compile(r"DROP .*INDEX ([a-z_]+)", flags=re.IGNORECASE) TABLE_CREATION_REGEX = re.compile(r"CREATE .*TABLE ([a-z_]+)", flags=re.IGNORECASE) +# The base branch we want to check against. We use the main development branch +# on the assumption that is what we are developing against. +DEVELOP_BRANCH = "develop" + @click.command() @click.option( @@ -38,17 +42,17 @@ def main(force_colors: bool) -> None: click.secho("Updating repo...") repo = git.Repo() - repo.remote().fetch(refspec="develop") + repo.remote().fetch(refspec=DEVELOP_BRANCH) click.secho("Getting current schema version...") - r = repo.git.show("origin/develop:synapse/storage/schema/__init__.py") + r = repo.git.show(f"origin/{DEVELOP_BRANCH}:synapse/storage/schema/__init__.py") locals: Dict[str, Any] = {} exec(r, locals) current_schema_version = locals["SCHEMA_VERSION"] - diffs: List[git.Diff] = repo.remote().refs.develop.commit.diff(None) + diffs: List[git.Diff] = repo.remote().refs[DEVELOP_BRANCH].commit.diff(None) # Get the schema version of the local file to check against current schema on develop with open("synapse/storage/schema/__init__.py") as file: @@ -61,7 +65,7 @@ def main(force_colors: bool) -> None: # 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!", + f"The proposed schema version has diverged more than one version from {DEVELOP_BRANCH}, please fix!", fg="red", bold=True, color=force_colors,