"""complete_sync

Revision ID: 0adbe75a0b3f
Revises: 
Create Date: 2026-02-09 17:49:12.955967

"""
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 = '0adbe75a0b3f'
down_revision: Union[str, Sequence[str], None] = None
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('badges',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.String(), nullable=False),
    sa.Column('icon_url', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    schema='data'
    )
    op.create_index(op.f('ix_data_badges_id'), 'badges', ['id'], unique=False, schema='data')
    op.create_table('exchange_rates',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('base_currency', sa.String(length=3), nullable=True),
    sa.Column('target_currency', sa.String(length=3), nullable=True),
    sa.Column('rate', sa.Numeric(precision=18, scale=6), nullable=True),
    sa.Column('rate_date', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('geo_postal_codes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('country_code', sa.String(length=5), nullable=True),
    sa.Column('zip_code', sa.String(length=10), nullable=False),
    sa.Column('city', sa.String(length=100), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('geo_street_types',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    schema='data'
    )
    op.create_table('level_configs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('level_number', sa.Integer(), nullable=False),
    sa.Column('min_points', sa.Integer(), nullable=False),
    sa.Column('rank_name', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('level_number'),
    schema='data'
    )
    op.create_index(op.f('ix_data_level_configs_id'), 'level_configs', ['id'], unique=False, schema='data')
    op.create_table('point_rules',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('action_key', sa.String(), nullable=False),
    sa.Column('points', sa.Integer(), nullable=False),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_point_rules_action_key'), 'point_rules', ['action_key'], unique=True, schema='data')
    op.create_index(op.f('ix_data_point_rules_id'), 'point_rules', ['id'], unique=False, schema='data')
    op.create_table('regional_settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('country_code', sa.String(), nullable=False),
    sa.Column('currency', sa.String(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('country_code'),
    schema='data'
    )
    op.create_index(op.f('ix_data_regional_settings_id'), 'regional_settings', ['id'], unique=False, schema='data')
    op.create_table('service_specialties',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('slug', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['parent_id'], ['data.service_specialties.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('slug'),
    schema='data'
    )
    op.create_table('subscription_tiers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('rules', sa.JSON(), nullable=True),
    sa.Column('is_custom', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    schema='data'
    )
    op.create_table('system_parameters',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('key', sa.String(length=50), nullable=True),
    sa.Column('value', sa.JSON(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('description', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_system_parameters_id'), 'system_parameters', ['id'], unique=False, schema='data')
    op.create_index(op.f('ix_data_system_parameters_key'), 'system_parameters', ['key'], unique=True, schema='data')
    op.create_table('vehicle_catalog',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('make', sa.String(), nullable=False),
    sa.Column('model', sa.String(), nullable=False),
    sa.Column('generation', sa.String(), nullable=True),
    sa.Column('year_from', sa.Integer(), nullable=True),
    sa.Column('year_to', sa.Integer(), nullable=True),
    sa.Column('vehicle_class', sa.String(), nullable=True),
    sa.Column('fuel_type', sa.String(), nullable=True),
    sa.Column('engine_code', sa.String(), nullable=True),
    sa.Column('factory_data', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_vehicle_catalog_id'), 'vehicle_catalog', ['id'], unique=False, schema='data')
    op.create_index(op.f('ix_data_vehicle_catalog_make'), 'vehicle_catalog', ['make'], unique=False, schema='data')
    op.create_index(op.f('ix_data_vehicle_catalog_model'), 'vehicle_catalog', ['model'], unique=False, schema='data')
    op.create_table('addresses',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('postal_code_id', sa.Integer(), nullable=True),
    sa.Column('street_name', sa.String(length=200), nullable=False),
    sa.Column('street_type', sa.String(length=50), nullable=False),
    sa.Column('house_number', sa.String(length=50), nullable=False),
    sa.Column('stairwell', sa.String(length=20), nullable=True),
    sa.Column('floor', sa.String(length=20), nullable=True),
    sa.Column('door', sa.String(length=20), nullable=True),
    sa.Column('parcel_id', sa.String(length=50), nullable=True),
    sa.Column('full_address_text', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['postal_code_id'], ['data.geo_postal_codes.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('assets',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('vin', sa.String(length=17), nullable=False),
    sa.Column('license_plate', sa.String(length=20), nullable=True),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('year_of_manufacture', sa.Integer(), nullable=True),
    sa.Column('catalog_id', sa.Integer(), nullable=True),
    sa.Column('is_verified', sa.Boolean(), nullable=True),
    sa.Column('status', sa.String(length=20), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['catalog_id'], ['data.vehicle_catalog.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_assets_license_plate'), 'assets', ['license_plate'], unique=False, schema='data')
    op.create_index(op.f('ix_data_assets_vin'), 'assets', ['vin'], unique=True, schema='data')
    op.create_table('geo_streets',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('postal_code_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=200), nullable=False),
    sa.ForeignKeyConstraint(['postal_code_id'], ['data.geo_postal_codes.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('asset_events',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=False),
    sa.Column('event_type', sa.String(length=50), nullable=False),
    sa.Column('recorded_mileage', sa.Integer(), nullable=True),
    sa.Column('data', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('asset_financials',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=True),
    sa.Column('acquisition_price', sa.Numeric(precision=18, scale=2), nullable=True),
    sa.Column('acquisition_date', sa.DateTime(), nullable=True),
    sa.Column('financing_type', sa.String(), nullable=True),
    sa.Column('residual_value_estimate', sa.Numeric(precision=18, scale=2), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('asset_id'),
    schema='data'
    )
    op.create_table('asset_telemetry',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=True),
    sa.Column('current_mileage', sa.Integer(), nullable=True),
    sa.Column('mileage_unit', sa.String(length=10), nullable=True),
    sa.Column('vqi_score', sa.Numeric(precision=5, scale=2), nullable=True),
    sa.Column('dbs_score', sa.Numeric(precision=5, scale=2), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('asset_id'),
    schema='data'
    )
    op.create_table('persons',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('id_uuid', sa.UUID(), nullable=False),
    sa.Column('address_id', sa.UUID(), nullable=True),
    sa.Column('last_name', sa.String(), nullable=False),
    sa.Column('first_name', sa.String(), nullable=False),
    sa.Column('mothers_last_name', sa.String(), nullable=True),
    sa.Column('mothers_first_name', sa.String(), nullable=True),
    sa.Column('birth_place', sa.String(), nullable=True),
    sa.Column('birth_date', sa.DateTime(), nullable=True),
    sa.Column('phone', sa.String(), nullable=True),
    sa.Column('identity_docs', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.Column('medical_emergency', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.Column('ice_contact', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['address_id'], ['data.addresses.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('id_uuid'),
    schema='data'
    )
    op.create_index(op.f('ix_data_persons_id'), 'persons', ['id'], unique=False, schema='data')
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(), nullable=False),
    sa.Column('hashed_password', sa.String(), nullable=True),
    sa.Column('role', sa.Enum('admin', 'user', 'service', 'fleet_manager', 'driver', name='userrole'), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('region_code', sa.String(), nullable=True),
    sa.Column('is_deleted', sa.Boolean(), nullable=True),
    sa.Column('person_id', sa.BigInteger(), nullable=True),
    sa.Column('preferred_language', sa.String(length=5), nullable=True),
    sa.Column('preferred_currency', sa.String(length=3), nullable=True),
    sa.Column('timezone', sa.String(length=50), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['person_id'], ['data.persons.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_users_email'), 'users', ['email'], unique=True, schema='data')
    op.create_index(op.f('ix_data_users_id'), 'users', ['id'], unique=False, schema='data')
    op.create_table('asset_reviews',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('overall_rating', sa.Integer(), nullable=True),
    sa.Column('criteria_scores', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.Column('comment', sa.Text(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('audit_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('target_type', sa.String(), nullable=True),
    sa.Column('target_id', sa.String(), nullable=True),
    sa.Column('action', sa.String(), nullable=False),
    sa.Column('changes', sa.JSON(), nullable=True),
    sa.Column('timestamp', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_audit_logs_id'), 'audit_logs', ['id'], unique=False, schema='data')
    op.create_index(op.f('ix_data_audit_logs_target_id'), 'audit_logs', ['target_id'], unique=False, schema='data')
    op.create_index(op.f('ix_data_audit_logs_target_type'), 'audit_logs', ['target_type'], unique=False, schema='data')
    op.create_table('documents',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('parent_type', sa.String(length=20), nullable=False),
    sa.Column('parent_id', sa.String(length=50), nullable=False),
    sa.Column('doc_type', sa.String(length=50), nullable=True),
    sa.Column('original_name', sa.String(length=255), nullable=False),
    sa.Column('file_hash', sa.String(length=64), nullable=False),
    sa.Column('file_ext', sa.String(length=10), nullable=True),
    sa.Column('mime_type', sa.String(length=100), nullable=True),
    sa.Column('file_size', sa.Integer(), nullable=True),
    sa.Column('has_thumbnail', sa.Boolean(), nullable=True),
    sa.Column('thumbnail_path', sa.String(length=255), nullable=True),
    sa.Column('uploaded_by', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['uploaded_by'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('organizations',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('address_id', sa.UUID(), nullable=True),
    sa.Column('full_name', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('display_name', sa.String(length=50), nullable=True),
    sa.Column('default_currency', sa.String(length=3), nullable=True),
    sa.Column('country_code', sa.String(length=2), nullable=True),
    sa.Column('language', sa.String(length=5), nullable=True),
    sa.Column('address_zip', sa.String(length=10), nullable=True),
    sa.Column('address_city', sa.String(length=100), nullable=True),
    sa.Column('address_street_name', sa.String(length=150), nullable=True),
    sa.Column('address_street_type', sa.String(length=50), nullable=True),
    sa.Column('address_house_number', sa.String(length=20), nullable=True),
    sa.Column('address_hrsz', sa.String(length=50), nullable=True),
    sa.Column('address_stairwell', sa.String(length=20), nullable=True),
    sa.Column('address_floor', sa.String(length=20), nullable=True),
    sa.Column('address_door', sa.String(length=20), nullable=True),
    sa.Column('tax_number', sa.String(length=20), nullable=True),
    sa.Column('reg_number', sa.String(length=50), nullable=True),
    sa.Column('org_type', postgresql.ENUM('individual', 'service', 'service_provider', 'fleet_owner', 'club', 'business', name='orgtype', schema='data', inherit_schema=True), nullable=True),
    sa.Column('status', sa.String(length=30), nullable=True),
    sa.Column('is_deleted', sa.Boolean(), nullable=True),
    sa.Column('notification_settings', sa.JSON(), server_default=sa.text('\'{ "notify_owner": true, "alert_days_before": [30, 15, 7, 1] }\'::jsonb'), nullable=True),
    sa.Column('external_integration_config', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.Column('owner_id', sa.Integer(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('is_transferable', sa.Boolean(), nullable=True),
    sa.Column('is_verified', sa.Boolean(), nullable=True),
    sa.Column('verification_expires_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.ForeignKeyConstraint(['address_id'], ['data.addresses.id'], ),
    sa.ForeignKeyConstraint(['owner_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_organizations_id'), 'organizations', ['id'], unique=False, schema='data')
    op.create_index(op.f('ix_data_organizations_tax_number'), 'organizations', ['tax_number'], unique=True, schema='data')
    op.create_table('points_ledger',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('points', sa.Integer(), nullable=False),
    sa.Column('reason', sa.String(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_points_ledger_id'), 'points_ledger', ['id'], unique=False, schema='data')
    op.create_table('ratings',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('author_id', sa.Integer(), nullable=False),
    sa.Column('target_type', sa.String(length=20), nullable=False),
    sa.Column('target_id', sa.UUID(), nullable=False),
    sa.Column('score', sa.Integer(), nullable=False),
    sa.Column('comment', sa.String(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('user_badges',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('badge_id', sa.Integer(), nullable=False),
    sa.Column('earned_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['badge_id'], ['data.badges.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_user_badges_id'), 'user_badges', ['id'], unique=False, schema='data')
    op.create_table('user_stats',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('total_xp', sa.Integer(), nullable=False),
    sa.Column('social_points', sa.Integer(), nullable=False),
    sa.Column('current_level', sa.Integer(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('user_id'),
    schema='data'
    )
    op.create_table('vehicle_ownerships',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('vehicle_id', sa.UUID(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('start_date', sa.Date(), nullable=False),
    sa.Column('end_date', sa.Date(), nullable=True),
    sa.Column('notes', sa.Text(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.ForeignKeyConstraint(['vehicle_id'], ['data.assets.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_vehicle_ownerships_id'), 'vehicle_ownerships', ['id'], unique=False, schema='data')
    op.create_table('verification_tokens',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('token', sa.UUID(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('token_type', sa.String(length=20), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('is_used', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('token'),
    schema='data'
    )
    op.create_index(op.f('ix_data_verification_tokens_id'), 'verification_tokens', ['id'], unique=False, schema='data')
    op.create_table('wallets',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('coin_balance', sa.Numeric(precision=18, scale=2), nullable=True),
    sa.Column('credit_balance', sa.Numeric(precision=18, scale=2), nullable=True),
    sa.Column('currency', sa.String(length=3), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('user_id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_wallets_id'), 'wallets', ['id'], unique=False, schema='data')
    op.create_table('asset_assignments',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=False),
    sa.Column('assigned_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('released_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('status', sa.String(length=30), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['data.organizations.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('asset_costs',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('asset_id', sa.UUID(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=False),
    sa.Column('driver_id', sa.Integer(), nullable=True),
    sa.Column('cost_type', sa.String(length=50), nullable=False),
    sa.Column('amount', sa.Numeric(precision=18, scale=2), nullable=False),
    sa.Column('currency', sa.String(length=3), nullable=True),
    sa.Column('net_amount', sa.Numeric(precision=18, scale=2), nullable=True),
    sa.Column('vat_rate', sa.Numeric(precision=5, scale=2), nullable=True),
    sa.Column('exchange_rate_at_cost', sa.Numeric(precision=18, scale=6), nullable=True),
    sa.Column('date', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('mileage_at_cost', sa.Integer(), nullable=True),
    sa.Column('data', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.ForeignKeyConstraint(['asset_id'], ['data.assets.id'], ),
    sa.ForeignKeyConstraint(['driver_id'], ['data.users.id'], ),
    sa.ForeignKeyConstraint(['organization_id'], ['data.organizations.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('credit_logs',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('org_id', sa.Integer(), nullable=True),
    sa.Column('amount', sa.Numeric(precision=10, scale=2), nullable=True),
    sa.Column('description', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['org_id'], ['data.organizations.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('org_subscriptions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('org_id', sa.Integer(), nullable=True),
    sa.Column('tier_id', sa.Integer(), nullable=True),
    sa.Column('valid_from', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('valid_until', sa.DateTime(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['org_id'], ['data.organizations.id'], ),
    sa.ForeignKeyConstraint(['tier_id'], ['data.subscription_tiers.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_table('organization_members',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('organization_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('role', sa.String(), nullable=True),
    sa.Column('permissions', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
    sa.ForeignKeyConstraint(['organization_id'], ['data.organizations.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['data.users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    schema='data'
    )
    op.create_index(op.f('ix_data_organization_members_id'), 'organization_members', ['id'], unique=False, schema='data')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_data_organization_members_id'), table_name='organization_members', schema='data')
    op.drop_table('organization_members', schema='data')
    op.drop_table('org_subscriptions', schema='data')
    op.drop_table('credit_logs', schema='data')
    op.drop_table('asset_costs', schema='data')
    op.drop_table('asset_assignments', schema='data')
    op.drop_index(op.f('ix_data_wallets_id'), table_name='wallets', schema='data')
    op.drop_table('wallets', schema='data')
    op.drop_index(op.f('ix_data_verification_tokens_id'), table_name='verification_tokens', schema='data')
    op.drop_table('verification_tokens', schema='data')
    op.drop_index(op.f('ix_data_vehicle_ownerships_id'), table_name='vehicle_ownerships', schema='data')
    op.drop_table('vehicle_ownerships', schema='data')
    op.drop_table('user_stats', schema='data')
    op.drop_index(op.f('ix_data_user_badges_id'), table_name='user_badges', schema='data')
    op.drop_table('user_badges', schema='data')
    op.drop_table('ratings', schema='data')
    op.drop_index(op.f('ix_data_points_ledger_id'), table_name='points_ledger', schema='data')
    op.drop_table('points_ledger', schema='data')
    op.drop_index(op.f('ix_data_organizations_tax_number'), table_name='organizations', schema='data')
    op.drop_index(op.f('ix_data_organizations_id'), table_name='organizations', schema='data')
    op.drop_table('organizations', schema='data')
    op.drop_table('documents', schema='data')
    op.drop_index(op.f('ix_data_audit_logs_target_type'), table_name='audit_logs', schema='data')
    op.drop_index(op.f('ix_data_audit_logs_target_id'), table_name='audit_logs', schema='data')
    op.drop_index(op.f('ix_data_audit_logs_id'), table_name='audit_logs', schema='data')
    op.drop_table('audit_logs', schema='data')
    op.drop_table('asset_reviews', schema='data')
    op.drop_index(op.f('ix_data_users_id'), table_name='users', schema='data')
    op.drop_index(op.f('ix_data_users_email'), table_name='users', schema='data')
    op.drop_table('users', schema='data')
    op.drop_index(op.f('ix_data_persons_id'), table_name='persons', schema='data')
    op.drop_table('persons', schema='data')
    op.drop_table('asset_telemetry', schema='data')
    op.drop_table('asset_financials', schema='data')
    op.drop_table('asset_events', schema='data')
    op.drop_table('geo_streets', schema='data')
    op.drop_index(op.f('ix_data_assets_vin'), table_name='assets', schema='data')
    op.drop_index(op.f('ix_data_assets_license_plate'), table_name='assets', schema='data')
    op.drop_table('assets', schema='data')
    op.drop_table('addresses', schema='data')
    op.drop_index(op.f('ix_data_vehicle_catalog_model'), table_name='vehicle_catalog', schema='data')
    op.drop_index(op.f('ix_data_vehicle_catalog_make'), table_name='vehicle_catalog', schema='data')
    op.drop_index(op.f('ix_data_vehicle_catalog_id'), table_name='vehicle_catalog', schema='data')
    op.drop_table('vehicle_catalog', schema='data')
    op.drop_index(op.f('ix_data_system_parameters_key'), table_name='system_parameters', schema='data')
    op.drop_index(op.f('ix_data_system_parameters_id'), table_name='system_parameters', schema='data')
    op.drop_table('system_parameters', schema='data')
    op.drop_table('subscription_tiers', schema='data')
    op.drop_table('service_specialties', schema='data')
    op.drop_index(op.f('ix_data_regional_settings_id'), table_name='regional_settings', schema='data')
    op.drop_table('regional_settings', schema='data')
    op.drop_index(op.f('ix_data_point_rules_id'), table_name='point_rules', schema='data')
    op.drop_index(op.f('ix_data_point_rules_action_key'), table_name='point_rules', schema='data')
    op.drop_table('point_rules', schema='data')
    op.drop_index(op.f('ix_data_level_configs_id'), table_name='level_configs', schema='data')
    op.drop_table('level_configs', schema='data')
    op.drop_table('geo_street_types', schema='data')
    op.drop_table('geo_postal_codes', schema='data')
    op.drop_table('exchange_rates', schema='data')
    op.drop_index(op.f('ix_data_badges_id'), table_name='badges', schema='data')
    op.drop_table('badges', schema='data')
    # ### end Alembic commands ###
