New modules: - Energy Quota Management (定额管理) - Cost/Expense Analysis with TOU pricing (费用分析) - Sub-item Energy Analysis (分项分析) - EV Charging Station Management (充电桩管理) — 8 models, 6 pages - Enhanced Energy Analysis — loss, YoY, MoM comparison - Alarm Analytics — trends, MTTR, top devices, rule toggle - Maintenance & Work Orders (运维管理) — inspections, repair orders, duty - Data Query Module (数据查询) - Equipment Topology (设备拓扑) - Management System (管理体系) — regulations, standards, processes Infrastructure: - Redis caching layer with decorator - Redis Streams data ingestion buffer - Hourly/daily/monthly aggregation engine - Rate limiting & request ID middleware - 6 Alembic migrations (003-008), 21 new tables - Extended seed data for all modules Stats: 120+ API routes, 12 pages, 27 tabs, 37 database tables Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from logging.config import fileConfig
|
|
from sqlalchemy import engine_from_config, pool
|
|
from alembic import context
|
|
import sys
|
|
import os
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
from app.core.config import get_settings
|
|
from app.core.database import Base
|
|
from app.models import * # noqa
|
|
|
|
config = context.config
|
|
if config.config_file_name is not None:
|
|
fileConfig(config.config_file_name)
|
|
|
|
# Override sqlalchemy.url from app settings (supports .env override)
|
|
app_settings = get_settings()
|
|
config.set_main_option("sqlalchemy.url", app_settings.DATABASE_URL_SYNC)
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
|
|
def run_migrations_offline():
|
|
url = config.get_main_option("sqlalchemy.url")
|
|
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online():
|
|
connectable = engine_from_config(
|
|
config.get_section(config.config_ini_section, {}),
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
with connectable.connect() as connection:
|
|
context.configure(
|
|
connection=connection,
|
|
target_metadata=target_metadata,
|
|
render_as_batch=True,
|
|
)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|