From 1660826444554bb4e99c1b15d9e229f22bdfe8d0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 6 Oct 2025 16:32:09 +0100 Subject: [PATCH 1/4] Fix CREATE TABLE regex to handle IF NOT EXISTS --- scripts-dev/check_schema_delta.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 454784c3ae9..ebde5b8b20c 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -11,9 +11,13 @@ 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_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) +INDEX_CREATION_REGEX = re.compile( + r"CREATE .*INDEX .*ON ([a-z_0-9]+)", flags=re.IGNORECASE +) +INDEX_DELETION_REGEX = re.compile(r"DROP .*INDEX ([a-z_0-9]+)", flags=re.IGNORECASE) +TABLE_CREATION_REGEX = re.compile( + r"CREATE .*TABLE.* ([a-z_0-9]+)\s*\(", 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. From f9003c89f0df598f30be5d5af53f90467c9314d6 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 6 Oct 2025 16:34:13 +0100 Subject: [PATCH 2/4] Test schema file --- .../storage/schema/main/delta/92/00_test1.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 synapse/storage/schema/main/delta/92/00_test1.sql diff --git a/synapse/storage/schema/main/delta/92/00_test1.sql b/synapse/storage/schema/main/delta/92/00_test1.sql new file mode 100644 index 00000000000..55b64752d7a --- /dev/null +++ b/synapse/storage/schema/main/delta/92/00_test1.sql @@ -0,0 +1,20 @@ +CREATE TABLE test1 ( + id INT +); + +CREATE INDEX test1_id_idx ON test1 (id); + +CREATE TABLE IF NOT EXISTS test2 ( + id INT +); + +CREATE INDEX test2_id_idx ON test2 (id); +CREATE INDEX IF NOT EXISTS test2_id_idx ON test2 (id); + +CREATE INDEX CONCURRENTLY IF NOT EXISTS test3_id_idx ON test3 (id); + +CREATE TEMPORARY TABLE IF NOT EXSTS test4 ( + id INT +); + +CREATE INDEX IF NOT EXISTS test4_id_idx ON test4 (id); From 2688f8b7a97ee9f1336c905fbf20f492d6944afe Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 6 Oct 2025 16:48:33 +0100 Subject: [PATCH 3/4] Better diagnostics --- scripts-dev/check_schema_delta.py | 10 ++++++++-- synapse/storage/schema/main/delta/92/00_test1.sql | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index ebde5b8b20c..601089cd3a3 100755 --- a/scripts-dev/check_schema_delta.py +++ b/scripts-dev/check_schema_delta.py @@ -177,11 +177,14 @@ def main(force_colors: bool) -> None: clause = match.group() click.secho( - f"Found delta with index deletion: '{clause}' in {delta_file}\nThese should be in background updates.", + f"Found delta with index deletion: '{clause}' in {delta_file}", fg="red", bold=True, color=force_colors, ) + click.secho( + " ↪ These should be in background updates.", + ) return_code = 1 # Check for index creation, which is only allowed for tables we've @@ -192,11 +195,14 @@ def main(force_colors: bool) -> None: 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.", + f"Found delta with index creation for existing table: '{clause}' in {delta_file}", fg="red", bold=True, color=force_colors, ) + click.secho( + " ↪ These should be in background updates (or the table should be created in the same delta).", + ) return_code = 1 click.get_current_context().exit(return_code) diff --git a/synapse/storage/schema/main/delta/92/00_test1.sql b/synapse/storage/schema/main/delta/92/00_test1.sql index 55b64752d7a..abe806ce0d7 100644 --- a/synapse/storage/schema/main/delta/92/00_test1.sql +++ b/synapse/storage/schema/main/delta/92/00_test1.sql @@ -13,7 +13,7 @@ CREATE INDEX IF NOT EXISTS test2_id_idx ON test2 (id); CREATE INDEX CONCURRENTLY IF NOT EXISTS test3_id_idx ON test3 (id); -CREATE TEMPORARY TABLE IF NOT EXSTS test4 ( +CREATE TEMPORARY TABLE IF NOT EXISTS test4 ( id INT ); From b767d627c76baae0fee76f51108849c25504d8b8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 6 Oct 2025 16:50:40 +0100 Subject: [PATCH 4/4] Newsfile --- changelog.d/19020.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/19020.misc diff --git a/changelog.d/19020.misc b/changelog.d/19020.misc new file mode 100644 index 00000000000..f5775ff194d --- /dev/null +++ b/changelog.d/19020.misc @@ -0,0 +1 @@ +Fix CI linter for schema delta files to correctly handle all types of `CREATE TABLE` syntax.