analytics_0001_initial.py 762 B

12345678910111213141516171819202122232425262728293031323334
  1. """创建 Analytics 库基础表。"""
  2. from alembic import op
  3. from app.infrastructure.mysql.analytics_models import AnalyticsBase
  4. revision = "analytics_0001"
  5. down_revision = None
  6. branch_labels = None
  7. depends_on = None
  8. TABLE_NAMES = (
  9. "dim_date",
  10. "dim_product",
  11. "dim_salesperson",
  12. "fact_orders",
  13. "fact_policies",
  14. "metric_definitions",
  15. "analytics_sync_offsets",
  16. )
  17. def upgrade() -> None:
  18. bind = op.get_bind()
  19. for table in AnalyticsBase.metadata.sorted_tables:
  20. if table.name in TABLE_NAMES:
  21. table.create(bind=bind)
  22. def downgrade() -> None:
  23. bind = op.get_bind()
  24. for table in reversed(AnalyticsBase.metadata.sorted_tables):
  25. if table.name in TABLE_NAMES:
  26. table.drop(bind=bind)