Updates and fixes.

This commit is contained in:
2025-12-19 11:26:26 +01:00
parent 6c0dc5f3d8
commit 4ce795228d
28 changed files with 459 additions and 232 deletions

View File

@@ -4,7 +4,7 @@ WORKDIR /app
COPY pyproject.toml ./
RUN uv sync
RUN uv sync --no-cache
COPY . .

View File

@@ -1,83 +0,0 @@
"""add users table
Revision ID: 7c71d43d53e3
Revises: 4b84a36e13f5
Create Date: 2025-12-15 21:24:36.718471+00:00
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '7c71d43d53e3'
down_revision: Union[str, Sequence[str], None] = '4b84a36e13f5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('users',
sa.Column('id', sa.Text(), nullable=False),
sa.Column('username', sa.Text(), nullable=False),
sa.Column('email', sa.Text(), nullable=False),
sa.Column('password_hash', sa.Text(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('username')
)
op.create_index('idx_users_email', 'users', ['email'], unique=False)
op.create_index('idx_users_username', 'users', ['username'], unique=False)
op.drop_index(op.f('dashboard_l_is_defa_033b71_idx'), table_name='dashboard_layouts')
op.drop_index(op.f('dashboard_l_name_c36020_idx'), table_name='dashboard_layouts')
op.drop_index(op.f('dashboard_layouts_name_349f3640_like'), table_name='dashboard_layouts', postgresql_ops={'name': 'varchar_pattern_ops'})
op.drop_table('dashboard_layouts')
op.drop_table('django_migrations')
op.drop_table('iotDashboard_device')
op.drop_constraint(op.f('telemetry_device_id_fkey'), 'telemetry', type_='foreignkey')
op.create_foreign_key(None, 'telemetry', 'devices', ['device_id'], ['id'])
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'telemetry', type_='foreignkey')
op.create_foreign_key(op.f('telemetry_device_id_fkey'), 'telemetry', 'devices', ['device_id'], ['id'], ondelete='CASCADE')
op.create_table('iotDashboard_device',
sa.Column('id', sa.BIGINT(), sa.Identity(always=False, start=1, increment=1, minvalue=1, maxvalue=9223372036854775807, cycle=False, cache=1), autoincrement=True, nullable=False),
sa.Column('name', sa.VARCHAR(length=50), autoincrement=False, nullable=False),
sa.Column('ip', sa.VARCHAR(length=20), autoincrement=False, nullable=False),
sa.Column('protocol', sa.VARCHAR(length=20), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('iotDashboard_device_pkey'))
)
op.create_table('django_migrations',
sa.Column('id', sa.BIGINT(), sa.Identity(always=False, start=1, increment=1, minvalue=1, maxvalue=9223372036854775807, cycle=False, cache=1), autoincrement=True, nullable=False),
sa.Column('app', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('applied', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('django_migrations_pkey'))
)
op.create_table('dashboard_layouts',
sa.Column('id', sa.BIGINT(), sa.Identity(always=False, start=1, increment=1, minvalue=1, maxvalue=9223372036854775807, cycle=False, cache=1), autoincrement=True, nullable=False),
sa.Column('name', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=False),
sa.Column('is_default', sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('dashboard_layouts_pkey')),
sa.UniqueConstraint('name', name=op.f('dashboard_layouts_name_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
)
op.create_index(op.f('dashboard_layouts_name_349f3640_like'), 'dashboard_layouts', ['name'], unique=False, postgresql_ops={'name': 'varchar_pattern_ops'})
op.create_index(op.f('dashboard_l_name_c36020_idx'), 'dashboard_layouts', ['name'], unique=False)
op.create_index(op.f('dashboard_l_is_defa_033b71_idx'), 'dashboard_layouts', ['is_default'], unique=False)
op.drop_index('idx_users_username', table_name='users')
op.drop_index('idx_users_email', table_name='users')
op.drop_table('users')
# ### end Alembic commands ###

View File

@@ -1,45 +0,0 @@
"""add cascade delete to telemetry foreign key
Revision ID: 1dfb0bb45f93
Revises: 7c71d43d53e3
Create Date: 2025-12-15 21:56:13.260281+00:00
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '1dfb0bb45f93'
down_revision: Union[str, Sequence[str], None] = '7c71d43d53e3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema - only update telemetry foreign key."""
# Drop old foreign key constraint
op.drop_constraint('telemetry_device_id_fkey', 'telemetry', type_='foreignkey')
# Add new foreign key constraint with CASCADE delete
op.create_foreign_key(
'telemetry_device_id_fkey',
'telemetry', 'devices',
['device_id'], ['id'],
ondelete='CASCADE'
)
def downgrade() -> None:
"""Downgrade schema - revert foreign key change."""
# Drop CASCADE foreign key
op.drop_constraint('telemetry_device_id_fkey', 'telemetry', type_='foreignkey')
# Add back original foreign key without CASCADE
op.create_foreign_key(
'telemetry_device_id_fkey',
'telemetry', 'devices',
['device_id'], ['id']
)

View File

@@ -6,5 +6,7 @@ readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"alembic>=1.17.0",
"dotenv>=0.9.9",
"sqlalchemy>=2.0.44",
"psycopg2-binary>=2.9.10",
]