From b4186f9949c568fb8507f1c881baaa8ce2f63b7e Mon Sep 17 00:00:00 2001 From: Josh Ferge Date: Thu, 18 Apr 2024 08:39:42 -0700 Subject: [PATCH] feat(replays): add migration for replay_id in discover (#5790) * feat(replays): add migration for replay_id in discover * Update group_loader.py * Update group_loader.py * style(lint): Auto commit lint changes * Update 0008_discover_add_replay_id.py * Rename 0008_discover_add_replay_id.py to 0009_discover_add_replay_id.py --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> --- snuba/migrations/group_loader.py | 1 + .../discover/0009_discover_add_replay_id.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 snuba/snuba_migrations/discover/0009_discover_add_replay_id.py diff --git a/snuba/migrations/group_loader.py b/snuba/migrations/group_loader.py index 07d25efe48..18e3b86dae 100644 --- a/snuba/migrations/group_loader.py +++ b/snuba/migrations/group_loader.py @@ -137,6 +137,7 @@ def get_migrations(self) -> Sequence[str]: "0006_discover_add_trace_id", "0007_discover_add_span_id", "0008_discover_fix_add_local_table", + "0009_discover_add_replay_id", ] diff --git a/snuba/snuba_migrations/discover/0009_discover_add_replay_id.py b/snuba/snuba_migrations/discover/0009_discover_add_replay_id.py new file mode 100644 index 0000000000..f86a3116bc --- /dev/null +++ b/snuba/snuba_migrations/discover/0009_discover_add_replay_id.py @@ -0,0 +1,44 @@ +from typing import Sequence + +from snuba.clickhouse.columns import UUID, Column +from snuba.clusters.storage_sets import StorageSetKey +from snuba.migrations import migration, operations +from snuba.migrations.columns import MigrationModifiers as Modifiers +from snuba.migrations.operations import OperationTarget + + +class Migration(migration.ClickhouseNodeMigration): + """ + Add replay_id to merge table + """ + + blocking = False + + def forwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.AddColumn( + storage_set=StorageSetKey.DISCOVER, + table_name=table_name, + column=Column("replay_id", UUID(Modifiers(nullable=True))), + after="span_id", + target=target, + ) + for table_name, target in [ + ("discover_local", OperationTarget.LOCAL), + ("discover_dist", OperationTarget.DISTRIBUTED), + ] + ] + + def backwards_ops(self) -> Sequence[operations.SqlOperation]: + return [ + operations.DropColumn( + storage_set=StorageSetKey.DISCOVER, + table_name=table_name, + column_name="replay_id", + target=target, + ) + for table_name, target in [ + ("discover_dist", OperationTarget.DISTRIBUTED), + ("discover_local", OperationTarget.LOCAL), + ] + ]