Add initial schema migration, with basic tempmon table clones

plus expose new tables in the admin
This commit is contained in:
Lance Edgar 2017-04-01 18:34:01 -05:00
parent e036abd313
commit e46b18f674
4 changed files with 329 additions and 2 deletions

View file

@ -0,0 +1,78 @@
"""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 ###

View file

@ -0,0 +1,82 @@
"""initial schema
Revision ID: e33a25dbaf07
Revises:
Create Date: 2017-04-01 15:27:22.495907
"""
# revision identifiers, used by Alembic.
revision = 'e33a25dbaf07'
down_revision = None
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
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('group',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', websauna.system.model.columns.UUID(), nullable=True),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('description', sa.String(length=256), nullable=True),
sa.Column('created_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('updated_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('group_data', websauna.system.model.columns.JSONB(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('pk_group')),
sa.UniqueConstraint('name', name=op.f('uq_group_name'))
)
op.create_table('user_activation',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('updated_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('expires_at', websauna.system.model.columns.UTCDateTime(), nullable=False),
sa.Column('code', sa.String(length=32), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_user_activation')),
sa.UniqueConstraint('code', name=op.f('uq_user_activation_code'))
)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('uuid', websauna.system.model.columns.UUID(), nullable=True),
sa.Column('username', sa.String(length=256), nullable=True),
sa.Column('email', sa.String(length=256), nullable=True),
sa.Column('password', sa.String(length=256), nullable=True),
sa.Column('created_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('updated_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('activated_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('enabled', sa.Boolean(name='user_enabled_binary'), nullable=True),
sa.Column('last_login_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('last_login_ip', websauna.system.model.columns.INET(length=50), nullable=True),
sa.Column('user_data', websauna.system.model.columns.JSONB(), nullable=True),
sa.Column('last_auth_sensitive_operation_at', websauna.system.model.columns.UTCDateTime(), nullable=True),
sa.Column('activation_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['activation_id'], ['user_activation.id'], name=op.f('fk_users_activation_id_user_activation')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_users')),
sa.UniqueConstraint('email', name=op.f('uq_users_email')),
sa.UniqueConstraint('username', name=op.f('uq_users_username'))
)
op.create_table('usergroup',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], name=op.f('fk_usergroup_group_id_group')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_usergroup_user_id_users')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_usergroup'))
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('usergroup')
op.drop_table('users')
op.drop_table('user_activation')
op.drop_table('group')
# ### end Alembic commands ###