- Add start/stop/restart/status commands to Makefile - Add health endpoint with uptime tracking - Add CLI module (esp32-web command) - Add initial database migration - Listen on all interfaces (0.0.0.0:5500) Bump version to 0.1.1
152 lines
6.9 KiB
Python
152 lines
6.9 KiB
Python
"""initial schema
|
|
|
|
Revision ID: 80ccb7597566
|
|
Revises:
|
|
Create Date: 2026-02-05 20:58:36.484000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '80ccb7597566'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('devices',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('mac', sa.String(length=17), nullable=False),
|
|
sa.Column('device_type', sa.String(length=8), nullable=False),
|
|
sa.Column('vendor', sa.String(length=64), nullable=True),
|
|
sa.Column('name', sa.String(length=64), nullable=True),
|
|
sa.Column('first_seen', sa.DateTime(), nullable=False),
|
|
sa.Column('last_seen', sa.DateTime(), nullable=False),
|
|
sa.Column('company_id', sa.Integer(), nullable=True),
|
|
sa.Column('tx_power', sa.Integer(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('devices', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_devices_mac'), ['mac'], unique=True)
|
|
|
|
op.create_table('sensors',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('hostname', sa.String(length=32), nullable=False),
|
|
sa.Column('ip', sa.String(length=15), nullable=False),
|
|
sa.Column('last_seen', sa.DateTime(), nullable=False),
|
|
sa.Column('status', sa.String(length=16), nullable=False),
|
|
sa.Column('config_json', sa.Text(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('sensors', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_sensors_hostname'), ['hostname'], unique=True)
|
|
|
|
op.create_table('alerts',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('sensor_id', sa.Integer(), nullable=False),
|
|
sa.Column('alert_type', sa.String(length=16), nullable=False),
|
|
sa.Column('source_mac', sa.String(length=17), nullable=True),
|
|
sa.Column('target_mac', sa.String(length=17), nullable=True),
|
|
sa.Column('rssi', sa.Integer(), nullable=True),
|
|
sa.Column('flood_count', sa.Integer(), nullable=True),
|
|
sa.Column('flood_window', sa.Integer(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['sensor_id'], ['sensors.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('alerts', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_alerts_alert_type'), ['alert_type'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_alerts_sensor_id'), ['sensor_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_alerts_timestamp'), ['timestamp'], unique=False)
|
|
|
|
op.create_table('events',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('sensor_id', sa.Integer(), nullable=False),
|
|
sa.Column('event_type', sa.String(length=32), nullable=False),
|
|
sa.Column('payload_json', sa.Text(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['sensor_id'], ['sensors.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('events', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_events_event_type'), ['event_type'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_events_sensor_id'), ['sensor_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_events_timestamp'), ['timestamp'], unique=False)
|
|
|
|
op.create_table('probes',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('device_id', sa.Integer(), nullable=False),
|
|
sa.Column('sensor_id', sa.Integer(), nullable=False),
|
|
sa.Column('ssid', sa.String(length=32), nullable=False),
|
|
sa.Column('rssi', sa.Integer(), nullable=False),
|
|
sa.Column('channel', sa.Integer(), nullable=False),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['device_id'], ['devices.id'], ),
|
|
sa.ForeignKeyConstraint(['sensor_id'], ['sensors.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('probes', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_probes_device_id'), ['device_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_probes_sensor_id'), ['sensor_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_probes_ssid'), ['ssid'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_probes_timestamp'), ['timestamp'], unique=False)
|
|
|
|
op.create_table('sightings',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('device_id', sa.Integer(), nullable=False),
|
|
sa.Column('sensor_id', sa.Integer(), nullable=False),
|
|
sa.Column('rssi', sa.Integer(), nullable=False),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['device_id'], ['devices.id'], ),
|
|
sa.ForeignKeyConstraint(['sensor_id'], ['sensors.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
with op.batch_alter_table('sightings', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_sightings_device_id'), ['device_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_sightings_sensor_id'), ['sensor_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_sightings_timestamp'), ['timestamp'], unique=False)
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade():
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table('sightings', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_sightings_timestamp'))
|
|
batch_op.drop_index(batch_op.f('ix_sightings_sensor_id'))
|
|
batch_op.drop_index(batch_op.f('ix_sightings_device_id'))
|
|
|
|
op.drop_table('sightings')
|
|
with op.batch_alter_table('probes', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_probes_timestamp'))
|
|
batch_op.drop_index(batch_op.f('ix_probes_ssid'))
|
|
batch_op.drop_index(batch_op.f('ix_probes_sensor_id'))
|
|
batch_op.drop_index(batch_op.f('ix_probes_device_id'))
|
|
|
|
op.drop_table('probes')
|
|
with op.batch_alter_table('events', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_events_timestamp'))
|
|
batch_op.drop_index(batch_op.f('ix_events_sensor_id'))
|
|
batch_op.drop_index(batch_op.f('ix_events_event_type'))
|
|
|
|
op.drop_table('events')
|
|
with op.batch_alter_table('alerts', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_alerts_timestamp'))
|
|
batch_op.drop_index(batch_op.f('ix_alerts_sensor_id'))
|
|
batch_op.drop_index(batch_op.f('ix_alerts_alert_type'))
|
|
|
|
op.drop_table('alerts')
|
|
with op.batch_alter_table('sensors', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_sensors_hostname'))
|
|
|
|
op.drop_table('sensors')
|
|
with op.batch_alter_table('devices', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_devices_mac'))
|
|
|
|
op.drop_table('devices')
|
|
# ### end Alembic commands ###
|