Files
roaauto/backend/alembic/versions/fbbfad4cd8f3_all_business_models.py
Marius Mutu 3a922a50e6 feat(backend): sync endpoints + all models + seed + order workflow
- All business models: Vehicle, Order, OrderLine, Invoice, Appointment,
  CatalogMarca/Model/Ansamblu/Norma/Pret/TipDeviz/TipMotor, Mecanic
- Sync endpoints: GET /sync/full, GET /sync/changes?since=, POST /sync/push
  with tenant isolation and last-write-wins conflict resolution
- Order CRUD with state machine: DRAFT -> VALIDAT -> FACTURAT
  Auto-recalculates totals (manopera + materiale)
- Vehicle CRUD: list, create, get, update
- Seed data: 24 marci, 11 ansamble, 6 tipuri deviz, 5 tipuri motoare, 3 preturi
- Alembic migration for all business models
- 13 passing tests (auth + sync + orders)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 17:31:02 +02:00

219 lines
11 KiB
Python

"""all_business_models
Revision ID: fbbfad4cd8f3
Revises: 88221cd8e1c3
Create Date: 2026-03-13 17:30:47.251556
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'fbbfad4cd8f3'
down_revision: Union[str, None] = '88221cd8e1c3'
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('appointments',
sa.Column('vehicle_id', sa.String(length=36), nullable=False),
sa.Column('data', sa.Text(), nullable=False),
sa.Column('descriere', sa.Text(), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_appointments_tenant_id'), 'appointments', ['tenant_id'], unique=False)
op.create_table('catalog_ansamble',
sa.Column('nume', sa.String(length=100), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_ansamble_tenant_id'), 'catalog_ansamble', ['tenant_id'], unique=False)
op.create_table('catalog_marci',
sa.Column('nume', sa.String(length=100), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_marci_tenant_id'), 'catalog_marci', ['tenant_id'], unique=False)
op.create_table('catalog_modele',
sa.Column('marca_id', sa.String(length=36), nullable=False),
sa.Column('nume', sa.String(length=100), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_modele_marca_id'), 'catalog_modele', ['marca_id'], unique=False)
op.create_table('catalog_norme',
sa.Column('ansamblu_id', sa.String(length=36), nullable=False),
sa.Column('descriere', sa.Text(), nullable=False),
sa.Column('ore', sa.Float(), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_norme_ansamblu_id'), 'catalog_norme', ['ansamblu_id'], unique=False)
op.create_index(op.f('ix_catalog_norme_tenant_id'), 'catalog_norme', ['tenant_id'], unique=False)
op.create_table('catalog_preturi',
sa.Column('denumire', sa.String(length=200), nullable=False),
sa.Column('pret', sa.Float(), nullable=False),
sa.Column('um', sa.String(length=10), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_preturi_tenant_id'), 'catalog_preturi', ['tenant_id'], unique=False)
op.create_table('catalog_tipuri_deviz',
sa.Column('nume', sa.String(length=100), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_tipuri_deviz_tenant_id'), 'catalog_tipuri_deviz', ['tenant_id'], unique=False)
op.create_table('catalog_tipuri_motoare',
sa.Column('nume', sa.String(length=50), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_tipuri_motoare_tenant_id'), 'catalog_tipuri_motoare', ['tenant_id'], unique=False)
op.create_table('invoices',
sa.Column('order_id', sa.String(length=36), nullable=False),
sa.Column('nr_factura', sa.String(length=50), nullable=False),
sa.Column('data_factura', sa.Text(), nullable=True),
sa.Column('total', sa.Float(), nullable=False),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_invoices_order_id'), 'invoices', ['order_id'], unique=False)
op.create_index(op.f('ix_invoices_tenant_id'), 'invoices', ['tenant_id'], unique=False)
op.create_table('mecanici',
sa.Column('nume', sa.String(length=200), nullable=False),
sa.Column('telefon', sa.String(length=20), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_mecanici_tenant_id'), 'mecanici', ['tenant_id'], unique=False)
op.create_table('order_lines',
sa.Column('order_id', sa.String(length=36), nullable=False),
sa.Column('tip', sa.String(length=20), nullable=False),
sa.Column('descriere', sa.Text(), nullable=False),
sa.Column('ore', sa.Float(), nullable=False),
sa.Column('pret_ora', sa.Float(), nullable=False),
sa.Column('cantitate', sa.Float(), nullable=False),
sa.Column('pret_unitar', sa.Float(), nullable=False),
sa.Column('um', sa.String(length=10), nullable=True),
sa.Column('total', sa.Float(), nullable=False),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_order_lines_order_id'), 'order_lines', ['order_id'], unique=False)
op.create_index(op.f('ix_order_lines_tenant_id'), 'order_lines', ['tenant_id'], unique=False)
op.create_table('orders',
sa.Column('vehicle_id', sa.String(length=36), nullable=False),
sa.Column('tip_deviz_id', sa.String(length=36), nullable=True),
sa.Column('status', sa.String(length=20), nullable=False),
sa.Column('data_comanda', sa.Text(), nullable=True),
sa.Column('km_intrare', sa.Integer(), nullable=True),
sa.Column('observatii', sa.Text(), nullable=True),
sa.Column('mecanic_id', sa.String(length=36), nullable=True),
sa.Column('total_manopera', sa.Float(), nullable=False),
sa.Column('total_materiale', sa.Float(), nullable=False),
sa.Column('total_general', sa.Float(), nullable=False),
sa.Column('token_client', sa.String(length=36), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_orders_tenant_id'), 'orders', ['tenant_id'], unique=False)
op.create_table('vehicles',
sa.Column('nr_inmatriculare', sa.String(length=20), nullable=False),
sa.Column('vin', sa.String(length=17), nullable=True),
sa.Column('marca_id', sa.String(length=36), nullable=True),
sa.Column('model_id', sa.String(length=36), nullable=True),
sa.Column('an_fabricatie', sa.Integer(), nullable=True),
sa.Column('tip_motor_id', sa.String(length=36), nullable=True),
sa.Column('capacitate_motor', sa.String(length=20), nullable=True),
sa.Column('putere_kw', sa.String(length=20), nullable=True),
sa.Column('client_nume', sa.String(length=200), nullable=True),
sa.Column('client_telefon', sa.String(length=20), nullable=True),
sa.Column('client_email', sa.String(length=200), nullable=True),
sa.Column('client_cui', sa.String(length=20), nullable=True),
sa.Column('client_adresa', sa.Text(), nullable=True),
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('tenant_id', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.Text(), nullable=False),
sa.Column('updated_at', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_vehicles_tenant_id'), 'vehicles', ['tenant_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_vehicles_tenant_id'), table_name='vehicles')
op.drop_table('vehicles')
op.drop_index(op.f('ix_orders_tenant_id'), table_name='orders')
op.drop_table('orders')
op.drop_index(op.f('ix_order_lines_tenant_id'), table_name='order_lines')
op.drop_index(op.f('ix_order_lines_order_id'), table_name='order_lines')
op.drop_table('order_lines')
op.drop_index(op.f('ix_mecanici_tenant_id'), table_name='mecanici')
op.drop_table('mecanici')
op.drop_index(op.f('ix_invoices_tenant_id'), table_name='invoices')
op.drop_index(op.f('ix_invoices_order_id'), table_name='invoices')
op.drop_table('invoices')
op.drop_index(op.f('ix_catalog_tipuri_motoare_tenant_id'), table_name='catalog_tipuri_motoare')
op.drop_table('catalog_tipuri_motoare')
op.drop_index(op.f('ix_catalog_tipuri_deviz_tenant_id'), table_name='catalog_tipuri_deviz')
op.drop_table('catalog_tipuri_deviz')
op.drop_index(op.f('ix_catalog_preturi_tenant_id'), table_name='catalog_preturi')
op.drop_table('catalog_preturi')
op.drop_index(op.f('ix_catalog_norme_tenant_id'), table_name='catalog_norme')
op.drop_index(op.f('ix_catalog_norme_ansamblu_id'), table_name='catalog_norme')
op.drop_table('catalog_norme')
op.drop_index(op.f('ix_catalog_modele_marca_id'), table_name='catalog_modele')
op.drop_table('catalog_modele')
op.drop_index(op.f('ix_catalog_marci_tenant_id'), table_name='catalog_marci')
op.drop_table('catalog_marci')
op.drop_index(op.f('ix_catalog_ansamble_tenant_id'), table_name='catalog_ansamble')
op.drop_table('catalog_ansamble')
op.drop_index(op.f('ix_appointments_tenant_id'), table_name='appointments')
op.drop_table('appointments')
# ### end Alembic commands ###