"""Init schema

Revision ID: 78371c256762
Revises: 
Create Date: 2024-08-21 00:35:06.960907

"""

from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "78371c256762"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "measurement_electricity",
        sa.Column("measured_ts", sa.DateTime(), nullable=True),
        sa.Column("value", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "measured_ts"),
    )
    op.create_table(
        "measurement_heat",
        sa.Column("measured_ts", sa.DateTime(), nullable=True),
        sa.Column("value", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "measured_ts"),
    )
    op.create_table(
        "measurement_raw",
        sa.Column("data", postgresql.JSON(astext_type=sa.Text()), nullable=True),
        sa.Column("type", sa.SmallInteger(), nullable=True),
        sa.Column("is_processed", sa.Boolean(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "measurement_water",
        sa.Column("measured_ts", sa.DateTime(), nullable=True),
        sa.Column("value", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "measured_ts"),
    )
    op.create_table(
        "usage_electricity_daily",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    op.create_table(
        "usage_electricity_monthly",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    op.create_table(
        "usage_heat_daily",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    op.create_table(
        "usage_heat_monthly",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    op.create_table(
        "usage_water_daily",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    op.create_table(
        "usage_water_monthly",
        sa.Column("start_ts", sa.DateTime(), nullable=True),
        sa.Column("end_ts", sa.DateTime(), nullable=True),
        sa.Column("consumption_ts", sa.DateTime(), nullable=True),
        sa.Column("start_value", sa.Float(), nullable=True),
        sa.Column("end_value", sa.Float(), nullable=True),
        sa.Column("consumption", sa.Float(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("tenant", sa.UUID(), nullable=True),
        sa.Column("external_id", sa.Text(), nullable=True),
        sa.Column("meter_id", sa.Text(), nullable=True),
        sa.Column("created_ts", sa.DateTime(), nullable=True),
        sa.Column("updated_ts", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("tenant", "meter_id", "consumption_ts"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("usage_water_monthly")
    op.drop_table("usage_water_daily")
    op.drop_table("usage_heat_monthly")
    op.drop_table("usage_heat_daily")
    op.drop_table("usage_electricity_monthly")
    op.drop_table("usage_electricity_daily")
    op.drop_table("measurement_water")
    op.drop_table("measurement_raw")
    op.drop_table("measurement_heat")
    op.drop_table("measurement_electricity")
    # ### end Alembic commands ###
