Skip to content

Commit

Permalink
Fix targetting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmanallen committed Jan 8, 2025
1 parent 35df5ee commit 246e395
Showing 1 changed file with 40 additions and 43 deletions.
83 changes: 40 additions & 43 deletions snuba/snuba_migrations/events/0025_add_features_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from snuba.migrations.operations import OperationTarget

table_names = [
("errors_local", StorageSetKey.EVENTS),
("errors_dist", StorageSetKey.EVENTS),
("errors_dist_ro", StorageSetKey.EVENTS_RO),
("errors_local", StorageSetKey.EVENTS, OperationTarget.LOCAL),
("errors_dist", StorageSetKey.EVENTS, OperationTarget.DISTRIBUTED),
("errors_dist_ro", StorageSetKey.EVENTS_RO, OperationTarget.DISTRIBUTED),
]
targets = [OperationTarget.LOCAL, OperationTarget.DISTRIBUTED]


class Migration(migration.ClickhouseNodeMigration):
Expand All @@ -27,32 +26,31 @@ def backwards_ops(self) -> Sequence[operations.SqlOperation]:

def forward_ops() -> Iterator[operations.SqlOperation]:
# Add local and dist columns for the three tables.
for target in targets:
for table_name, storage_set in table_names:
yield from [
operations.AddColumn(
storage_set=storage_set,
table_name=table_name,
column=Column(
"features", Nested([("key", String()), ("value", String())])
),
after="_tags_hash_map",
target=target,
for table_name, storage_set, target in table_names:
yield from [
operations.AddColumn(
storage_set=storage_set,
table_name=table_name,
column=Column(
"features", Nested([("key", String()), ("value", String())])
),
operations.AddColumn(
storage_set=storage_set,
table_name=table_name,
column=Column(
"_features_hash_map",
Array(
UInt(64),
Modifiers(materialized=FEATURES_HASH_MAP_COLUMN),
),
after="_tags_hash_map",
target=target,
),
operations.AddColumn(
storage_set=storage_set,
table_name=table_name,
column=Column(
"_features_hash_map",
Array(
UInt(64),
Modifiers(materialized=FEATURES_HASH_MAP_COLUMN),
),
after="features.value",
target=target,
),
]
after="features.value",
target=target,
),
]

# Add index to the local table.
yield operations.AddIndex(
Expand All @@ -74,19 +72,18 @@ def backward_ops() -> Iterator[operations.SqlOperation]:
target=OperationTarget.LOCAL,
)

for target in targets:
for table_name, storage_set in table_names:
yield from [
operations.DropColumn(
storage_set=storage_set,
table_name=table_name,
column_name="_features_hash_map",
target=target,
),
operations.DropColumn(
storage_set=storage_set,
table_name=table_name,
column_name="features",
target=target,
),
]
for table_name, storage_set, target in table_names:
yield from [
operations.DropColumn(
storage_set=storage_set,
table_name=table_name,
column_name="_features_hash_map",
target=target,
),
operations.DropColumn(
storage_set=storage_set,
table_name=table_name,
column_name="features",
target=target,
),
]

0 comments on commit 246e395

Please sign in to comment.