M8-T08: add WarmteLink reading schema
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""add normalized WarmteLink scalar reading history
|
||||
|
||||
Revision ID: 20260822_17_warmtelink_readings
|
||||
Revises: 20260822_16_dsmr_source_adoption
|
||||
Create Date: 2026-08-22 00:00:00.000000
|
||||
|
||||
The upgrade is additive: existing business rows are neither changed nor
|
||||
removed. The downgrade is schema-only and is exercised only on isolated test
|
||||
databases.
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision: str = "20260822_17_warmtelink_readings"
|
||||
down_revision: Union[str, None] = "20260822_16_dsmr_source_adoption"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"warmtelink_reading",
|
||||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column("channel_id", sa.Integer(), nullable=False),
|
||||
sa.Column("recorded_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("received_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("value", sa.Numeric(precision=15, scale=3), nullable=False),
|
||||
sa.Column("unit", sa.String(length=32), nullable=False),
|
||||
sa.Column("quality", sa.String(length=32), nullable=False),
|
||||
sa.Column("equipment_fingerprint", sa.String(length=64), nullable=False),
|
||||
sa.CheckConstraint(
|
||||
"quality IN ('valid', 'invalid', 'unverifiable')",
|
||||
name="ck_warmtelink_reading_quality",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["channel_id"], ["meter_source_channel.id"], ondelete="RESTRICT"
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint(
|
||||
"channel_id", "recorded_at", name="uq_warmtelink_reading_channel_recorded_at"
|
||||
),
|
||||
)
|
||||
op.create_index("ix_warmtelink_reading_recorded_at", "warmtelink_reading", ["recorded_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_warmtelink_reading_recorded_at", table_name="warmtelink_reading")
|
||||
op.drop_table("warmtelink_reading")
|
||||
Reference in New Issue
Block a user