Initial commit

This commit is contained in:
Lance Edgar 2016-12-05 19:06:34 -06:00
commit 7550e63940
19 changed files with 1654 additions and 0 deletions

View file

@ -0,0 +1 @@
Generic single-database configuration.

View file

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""
Alembic Environment Script
"""
from __future__ import unicode_literals, absolute_import
from alembic import context
from rattail.config import make_config
from rattail_tempmon.db import model as tempmon
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use
alembic_config = context.config
# Use same config file for Rattail, as we are for Alembic.
rattail_config = make_config(alembic_config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = tempmon.Base.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
engine = rattail_config.tempmon_engine
context.configure(
url=engine.url,
target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = rattail_config.tempmon_engine
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View file

@ -0,0 +1,30 @@
# -*- coding: utf-8; mode: python -*-
# -*- coding: utf-8 -*-
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from __future__ import unicode_literals, absolute_import
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
from alembic import op
import sqlalchemy as sa
import rattail.db.types
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View file

@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
"""initial tables
Revision ID: 7c7d205787b0
Revises:
Create Date: 2016-12-05 15:14:09.387668
"""
from __future__ import unicode_literals, absolute_import
# revision identifiers, used by Alembic.
revision = '7c7d205787b0'
down_revision = None
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# client
op.create_table('client',
sa.Column('uuid', sa.String(length=32), nullable=False),
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('enabled', sa.Boolean(), nullable=False),
sa.Column('online', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('uuid'),
sa.UniqueConstraint('config_key', name=u'client_uq_config_key')
)
# probe
op.create_table('probe',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('client_uuid', sa.String(length=32), nullable=False),
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', sa.DateTime(), nullable=True),
sa.Column('status_alert_sent', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['client_uuid'], [u'client.uuid'], name=u'probe_fk_client'),
sa.PrimaryKeyConstraint('uuid'),
sa.UniqueConstraint('config_key', name=u'probe_uq_config_key')
)
# tempmon reading
op.create_table('reading',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('client_uuid', sa.String(length=32), nullable=False),
sa.Column('probe_uuid', sa.String(length=32), nullable=False),
sa.Column('taken', sa.DateTime(), nullable=False),
sa.Column('degrees_f', sa.Numeric(precision=7, scale=4), nullable=False),
sa.ForeignKeyConstraint(['client_uuid'], [u'client.uuid'], name=u'reading_fk_client'),
sa.ForeignKeyConstraint(['probe_uuid'], [u'probe.uuid'], name=u'reading_fk_probe'),
sa.PrimaryKeyConstraint('uuid')
)
def downgrade():
op.drop_table('reading')
op.drop_table('probe')
op.drop_table('client')