diff --git a/snuba/migrations/operations.py b/snuba/migrations/operations.py index cc167d0b3c..d4f0e2ea03 100644 --- a/snuba/migrations/operations.py +++ b/snuba/migrations/operations.py @@ -517,15 +517,18 @@ def __init__( table_name: str, index_name: str, target: OperationTarget = OperationTarget.UNSET, + run_async: bool = False, ): super().__init__(storage_set, target=target) self.__table_name = table_name self.__index_name = index_name + self.__run_async = run_async def format_sql(self) -> str: - return ( - f"ALTER TABLE {self.__table_name} DROP INDEX IF EXISTS {self.__index_name};" - ) + settings = "" + if self.__run_async: + settings = " SETTINGS mutations_sync=0" + return f"ALTER TABLE {self.__table_name} DROP INDEX IF EXISTS {self.__index_name}{settings};" class DropIndices(SqlOperation): diff --git a/snuba/snuba_migrations/events_analytics_platform/0008_drop_index_attribute_key_bucket_0.py b/snuba/snuba_migrations/events_analytics_platform/0008_drop_index_attribute_key_bucket_0.py new file mode 100644 index 0000000000..bbd2e70dad --- /dev/null +++ b/snuba/snuba_migrations/events_analytics_platform/0008_drop_index_attribute_key_bucket_0.py @@ -0,0 +1,24 @@ +from typing import Sequence + +from snuba.clusters.storage_sets import StorageSetKey +from snuba.migrations import migration, operations + + +class Migration(migration.ClickhouseNodeMigration): + blocking = False + + def forwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.DropIndex( + storage_set=StorageSetKey.EVENTS_ANALYTICS_PLATFORM, + table_name="eap_spans_local", + index_name=index_name, + target=operations.OperationTarget.LOCAL, + run_async=True, + ) + for bucket in {0} + for index_name in {f"bf_attr_num_{bucket}", f"bf_attr_str_{bucket}"} + ] + + def backwards_ops(self) -> Sequence[operations.SqlOperation]: + return [] diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py index 529a6733ab..d492be3d2c 100644 --- a/tests/migrations/test_operations.py +++ b/tests/migrations/test_operations.py @@ -171,6 +171,15 @@ def test_drop_index() -> None: ) +def test_drop_index_async() -> None: + assert ( + DropIndex( + StorageSetKey.EVENTS, "test_table", "index_1", run_async=True + ).format_sql() + == "ALTER TABLE test_table DROP INDEX IF EXISTS index_1 SETTINGS mutations_sync=0;" + ) + + def test_insert_into_select() -> None: assert ( InsertIntoSelect(