79 lines
3.5 KiB
Python
79 lines
3.5 KiB
Python
|
"""initial tempmon tables
|
||
|
|
||
|
Revision ID: 9a0317b74dee
|
||
|
Revises: e33a25dbaf07
|
||
|
Create Date: 2017-04-01 15:58:27.513593
|
||
|
|
||
|
"""
|
||
|
|
||
|
# revision identifiers, used by Alembic.
|
||
|
revision = '9a0317b74dee'
|
||
|
down_revision = 'e33a25dbaf07'
|
||
|
branch_labels = None
|
||
|
depends_on = None
|
||
|
|
||
|
import datetime
|
||
|
import websauna.system.model.columns
|
||
|
from sqlalchemy.types import Text # Needed from proper creation of JSON fields as Alembic inserts astext_type=Text() row
|
||
|
|
||
|
from alembic import op
|
||
|
import sqlalchemy as sa
|
||
|
from sqlalchemy.dialects import postgresql
|
||
|
|
||
|
def upgrade():
|
||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
op.create_table('client',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=True),
|
||
|
sa.Column('config_key', sa.String(length=50), nullable=False),
|
||
|
sa.Column('hostname', sa.String(length=255), nullable=False),
|
||
|
sa.Column('location', sa.String(length=255), nullable=True),
|
||
|
sa.Column('delay', sa.Integer(), nullable=True),
|
||
|
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||
|
sa.Column('online', sa.Boolean(), nullable=False),
|
||
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_client')),
|
||
|
sa.UniqueConstraint('config_key', name=op.f('uq_client_config_key'))
|
||
|
)
|
||
|
op.create_table('probe',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=True),
|
||
|
sa.Column('client_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('config_key', sa.String(length=50), nullable=False),
|
||
|
sa.Column('appliance_type', sa.Integer(), nullable=False),
|
||
|
sa.Column('description', sa.String(length=255), nullable=False),
|
||
|
sa.Column('device_path', sa.String(length=255), nullable=True),
|
||
|
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||
|
sa.Column('good_temp_min', sa.Integer(), nullable=False),
|
||
|
sa.Column('good_temp_max', sa.Integer(), nullable=False),
|
||
|
sa.Column('critical_temp_min', sa.Integer(), nullable=False),
|
||
|
sa.Column('critical_temp_max', sa.Integer(), nullable=False),
|
||
|
sa.Column('therm_status_timeout', sa.Integer(), nullable=False),
|
||
|
sa.Column('status_alert_timeout', sa.Integer(), nullable=False),
|
||
|
sa.Column('status', sa.Integer(), nullable=True),
|
||
|
sa.Column('status_changed', websauna.system.model.columns.UTCDateTime(), nullable=True),
|
||
|
sa.Column('status_alert_sent', websauna.system.model.columns.UTCDateTime(), nullable=True),
|
||
|
sa.ForeignKeyConstraint(['client_id'], ['client.id'], name=op.f('fk_probe_client_id_client')),
|
||
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_probe')),
|
||
|
sa.UniqueConstraint('config_key', name=op.f('uq_probe_config_key'))
|
||
|
)
|
||
|
op.create_table('reading',
|
||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
sa.Column('uuid', postgresql.UUID(as_uuid=True), nullable=True),
|
||
|
sa.Column('client_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('probe_id', sa.Integer(), nullable=True),
|
||
|
sa.Column('taken', websauna.system.model.columns.UTCDateTime(), nullable=True),
|
||
|
sa.Column('degrees_f', sa.Numeric(precision=7, scale=4), nullable=False),
|
||
|
sa.ForeignKeyConstraint(['client_id'], ['client.id'], name=op.f('fk_reading_client_id_client')),
|
||
|
sa.ForeignKeyConstraint(['probe_id'], ['probe.id'], name=op.f('fk_reading_probe_id_probe')),
|
||
|
sa.PrimaryKeyConstraint('id', name=op.f('pk_reading'))
|
||
|
)
|
||
|
# ### end Alembic commands ###
|
||
|
|
||
|
|
||
|
def downgrade():
|
||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
op.drop_table('reading')
|
||
|
op.drop_table('probe')
|
||
|
op.drop_table('client')
|
||
|
# ### end Alembic commands ###
|