M0: implement operational core

Backend: SQLAlchemy models, Alembic migrations, requirements lockfile. Frontend: pinned deps, package-lock, vite-env types fix. Verified compose build/health, pytest, ruff clean.
This commit is contained in:
NuklearRabbit
2026-08-01 21:01:04 +02:00
parent 24188d9b10
commit 04d26f1f2e
24 changed files with 2539 additions and 14 deletions
+46
View File
@@ -0,0 +1,46 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config, pool
from alembic import context
from app.core.config import get_settings
from app.models import Base
config = context.config
if config.config_file_name is not None:
fileConfig(config.config_file_name)
settings = get_settings()
config.set_main_option("sqlalchemy.url", settings.database_url)
target_metadata = Base.metadata
def run_migrations_offline() -> None:
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
+26
View File
@@ -0,0 +1,26 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}
@@ -0,0 +1,184 @@
"""initial schema
Revision ID: c9498525abb5
Revises:
Create Date: 2026-08-01 20:50:05.997864
"""
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 = 'c9498525abb5'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('audit_events',
sa.Column('actor_type', sa.String(length=20), nullable=False),
sa.Column('actor_id', sa.UUID(), nullable=True),
sa.Column('actor_label', sa.String(length=120), nullable=False),
sa.Column('action', sa.String(length=80), nullable=False),
sa.Column('entity_type', sa.String(length=30), nullable=False),
sa.Column('entity_id', sa.UUID(), nullable=True),
sa.Column('correlation_id', sa.UUID(), nullable=False),
sa.Column('before_json', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('after_json', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('metadata_json', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('occurred_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('customers',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('first_name', sa.String(length=80), nullable=False),
sa.Column('last_name', sa.String(length=80), nullable=False),
sa.Column('email', sa.String(length=200), nullable=True),
sa.Column('phone', sa.String(length=40), nullable=True),
sa.Column('postal_code', sa.String(length=20), nullable=True),
sa.Column('city', sa.String(length=120), nullable=True),
sa.Column('date_of_birth', sa.Date(), nullable=True),
sa.Column('merged_into_customer_id', sa.UUID(), nullable=True),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['merged_into_customer_id'], ['customers.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
op.create_table('data_quality_issues',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('rule_type', sa.String(length=40), nullable=False),
sa.Column('entity_type', sa.String(length=30), nullable=False),
sa.Column('entity_id', sa.UUID(), nullable=False),
sa.Column('severity', sa.String(length=10), nullable=False),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('evidence_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('proposed_action_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('detected_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('resolved_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('resolved_by', sa.String(length=120), nullable=True),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
op.create_table('outbox_events',
sa.Column('event_id', sa.UUID(), nullable=False),
sa.Column('event_type', sa.String(length=60), nullable=False),
sa.Column('aggregate_type', sa.String(length=30), nullable=False),
sa.Column('aggregate_id', sa.UUID(), nullable=False),
sa.Column('payload_json', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('occurred_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('delivery_status', sa.String(length=20), nullable=False),
sa.Column('attempts', sa.Integer(), nullable=False),
sa.Column('next_attempt_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_error', sa.Text(), nullable=True),
sa.Column('external_run_id', sa.String(length=120), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('event_id')
)
op.create_table('users',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('display_name', sa.String(length=120), nullable=False),
sa.Column('role', sa.String(length=30), nullable=False),
sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
op.create_table('vehicles',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('make', sa.String(length=80), nullable=False),
sa.Column('model', sa.String(length=80), nullable=False),
sa.Column('model_year', sa.Integer(), nullable=False),
sa.Column('registration_number', sa.String(length=40), nullable=False),
sa.Column('location', sa.String(length=120), nullable=False),
sa.Column('operational_status', sa.String(length=20), nullable=False),
sa.Column('odometer_km', sa.Integer(), nullable=False),
sa.Column('next_service_km', sa.Integer(), nullable=False),
sa.Column('active', sa.Boolean(), nullable=False),
sa.Column('version', sa.Integer(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref'),
sa.UniqueConstraint('registration_number')
)
op.create_table('bookings',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('customer_id', sa.UUID(), nullable=False),
sa.Column('vehicle_id', sa.UUID(), nullable=False),
sa.Column('starts_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('ends_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('start_odometer_km', sa.Integer(), nullable=True),
sa.Column('end_odometer_km', sa.Integer(), nullable=True),
sa.Column('requirements_complete', sa.Boolean(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['customer_id'], ['customers.id'], ),
sa.ForeignKeyConstraint(['vehicle_id'], ['vehicles.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
op.create_table('maintenance_records',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('vehicle_id', sa.UUID(), nullable=False),
sa.Column('occurred_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('odometer_km', sa.Integer(), nullable=False),
sa.Column('category', sa.String(length=60), nullable=False),
sa.Column('summary', sa.Text(), nullable=False),
sa.Column('id', sa.UUID(), nullable=False),
sa.ForeignKeyConstraint(['vehicle_id'], ['vehicles.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
op.create_table('inspections',
sa.Column('public_ref', sa.String(length=20), nullable=False),
sa.Column('booking_id', sa.UUID(), nullable=False),
sa.Column('vehicle_id', sa.UUID(), nullable=False),
sa.Column('type', sa.String(length=20), nullable=False),
sa.Column('fuel_level_percent', sa.Integer(), nullable=False),
sa.Column('cleanliness_ok', sa.Boolean(), nullable=False),
sa.Column('damage_reported', sa.Boolean(), nullable=False),
sa.Column('technical_warning', sa.Boolean(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('odometer_km', sa.Integer(), nullable=False),
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('completed_by', sa.String(length=120), nullable=True),
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.ForeignKeyConstraint(['booking_id'], ['bookings.id'], ),
sa.ForeignKeyConstraint(['vehicle_id'], ['vehicles.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('public_ref')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('inspections')
op.drop_table('maintenance_records')
op.drop_table('bookings')
op.drop_table('vehicles')
op.drop_table('users')
op.drop_table('outbox_events')
op.drop_table('data_quality_issues')
op.drop_table('customers')
op.drop_table('audit_events')
# ### end Alembic commands ###