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. diff --git a/scripts-dev/check_schema_delta.py b/scripts-dev/check_schema_delta.py index 454784c3ae9..601089cd3a3 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. @@ -173,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 @@ -188,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 new file mode 100644 index 00000000000..abe806ce0d7 --- /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 EXISTS test4 ( + id INT +); + +CREATE INDEX IF NOT EXISTS test4_id_idx ON test4 (id);