diff --git a/snuba/migrations/group_loader.py b/snuba/migrations/group_loader.py index 728eb2683d..ef464378eb 100644 --- a/snuba/migrations/group_loader.py +++ b/snuba/migrations/group_loader.py @@ -317,6 +317,7 @@ def get_migrations(self) -> Sequence[str]: "0026_gauges_add_raw_tags_hash_column", "0027_sets_add_raw_tags_column", "0028_distributions_add_indexed_tags_column", + "0029_add_use_case_id_index", ] diff --git a/snuba/snuba_migrations/generic_metrics/0029_add_use_case_id_index.py b/snuba/snuba_migrations/generic_metrics/0029_add_use_case_id_index.py new file mode 100644 index 0000000000..13efd2f8f7 --- /dev/null +++ b/snuba/snuba_migrations/generic_metrics/0029_add_use_case_id_index.py @@ -0,0 +1,76 @@ +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.AddIndex( + storage_set=StorageSetKey.GENERIC_METRICS_COUNTERS, + table_name="generic_metric_counters_aggregated_local", + index_name="set_idx_use_case_id", + index_expression="use_case_id", + index_type="set(0)", + granularity=1, + target=operations.OperationTarget.LOCAL, + ), + operations.AddIndex( + storage_set=StorageSetKey.GENERIC_METRICS_SETS, + table_name="generic_metric_sets_local", + index_name="set_idx_use_case_id", + index_expression="use_case_id", + index_type="set(0)", + granularity=1, + target=operations.OperationTarget.LOCAL, + ), + operations.AddIndex( + storage_set=StorageSetKey.GENERIC_METRICS_DISTRIBUTIONS, + table_name="generic_metric_distributions_aggregated_local", + index_name="set_idx_use_case_id", + index_expression="use_case_id", + index_type="set(0)", + granularity=1, + target=operations.OperationTarget.LOCAL, + ), + operations.AddIndex( + storage_set=StorageSetKey.GENERIC_METRICS_GAUGES, + table_name="generic_metric_gauges_aggregated_local", + index_name="set_idx_use_case_id", + index_expression="use_case_id", + index_type="set(0)", + granularity=1, + target=operations.OperationTarget.LOCAL, + ), + ] + + def backwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.DropIndex( + storage_set=StorageSetKey.GENERIC_METRICS_GAUGES, + table_name="generic_metric_gauges_aggregated_local", + index_name="set_idx_use_case_id", + target=operations.OperationTarget.LOCAL, + ), + operations.DropIndex( + storage_set=StorageSetKey.GENERIC_METRICS_DISTRIBUTIONS, + table_name="generic_metric_distributions_aggregated_local", + index_name="set_idx_use_case_id", + target=operations.OperationTarget.LOCAL, + ), + operations.DropIndex( + storage_set=StorageSetKey.GENERIC_METRICS_COUNTERS, + table_name="generic_metric_counters_aggregated_local", + index_name="set_idx_use_case_id", + target=operations.OperationTarget.LOCAL, + ), + operations.DropIndex( + storage_set=StorageSetKey.GENERIC_METRICS_SETS, + table_name="generic_metric_sets_local", + index_name="set_idx_use_case_id", + target=operations.OperationTarget.LOCAL, + ), + ]