"""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 ###