Files
DecomEval/backend/alembic/versions/0009_celldata_lookup_index.py
nixevol 14d1b4c7bc feat: 工参表按 CGI 和基站 ID 加索引
CellData_4G 唯一索引改为 (cgi, snapshot_id),另加 (enodeb_id, snapshot_id);CellData_5G 对应 (ncgi, snapshot_id)、(gnodeb_id, snapshot_id),跨日期按小区或基站查询都能走索引。
2026-11-11 03:06:31 +08:00

30 lines
1.1 KiB
Python

"""按小区标识和基站 ID 跨快照查询:唯一索引改成小区标识在前,另加基站 ID 索引。"""
from alembic import op
revision = "0009_celldata_lookup_index"
down_revision = "0008_celldata_split"
branch_labels = None
depends_on = None
TABLES = (
("CellData_4G", "celldata_4g", "cgi", "enodeb_id", "enodeb"),
("CellData_5G", "celldata_5g", "ncgi", "gnodeb_id", "gnodeb"),
)
def upgrade() -> None:
for table, prefix, key, node, node_label in TABLES:
with op.batch_alter_table(table) as batch:
batch.drop_constraint(f"uq_{prefix}_{key}", type_="unique")
batch.create_unique_constraint(f"uq_{prefix}_{key}", [key, "snapshot_id"])
batch.create_index(f"ix_{prefix}_{node_label}", [node, "snapshot_id"])
def downgrade() -> None:
for table, prefix, key, node, node_label in TABLES:
with op.batch_alter_table(table) as batch:
batch.drop_index(f"ix_{prefix}_{node_label}")
batch.drop_constraint(f"uq_{prefix}_{key}", type_="unique")
batch.create_unique_constraint(f"uq_{prefix}_{key}", ["snapshot_id", key])