All checks were successful
Deploy to Production / deploy (push) Successful in 1m7s
- Add InspectionTemplate and InspectionTemplateItem models - Add 9 API endpoints for template CRUD and item management - Add Alembic migration for inspection_templates tables - Add 15 backend tests (39/39 total pass) - Add TemplateEditor component with item management UI - Add templates list, create, and edit pages - Add tab bar, template grid, form row CSS classes - Fix CORS middleware ordering in main.py - Move CORS middleware before router registration Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
77 lines
3.7 KiB
Python
77 lines
3.7 KiB
Python
"""add_inspection_templates
|
|
|
|
Revision ID: 9566bf2a256b
|
|
Revises: a3b1c2d3e4f5
|
|
Create Date: 2026-02-10 13:01:03.924293
|
|
|
|
"""
|
|
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 = '9566bf2a256b'
|
|
down_revision: Union[str, Sequence[str], None] = 'a3b1c2d3e4f5'
|
|
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('inspection_templates',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('tenant_id', sa.String(length=50), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('subject_type', sa.String(length=20), nullable=False),
|
|
sa.Column('machine_id', sa.UUID(), nullable=True),
|
|
sa.Column('product_code', sa.String(length=50), nullable=True),
|
|
sa.Column('schedule_type', sa.String(length=20), nullable=False),
|
|
sa.Column('inspection_mode', sa.String(length=20), nullable=True),
|
|
sa.Column('version', sa.Integer(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
|
|
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['machine_id'], ['machines.id'], ),
|
|
sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index('ix_templates_tenant_machine', 'inspection_templates', ['tenant_id', 'machine_id'], unique=False)
|
|
op.create_index('ix_templates_tenant_subject', 'inspection_templates', ['tenant_id', 'subject_type'], unique=False)
|
|
op.create_table('inspection_template_items',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('template_id', sa.UUID(), nullable=False),
|
|
sa.Column('sort_order', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('category', sa.String(length=100), nullable=True),
|
|
sa.Column('data_type', sa.String(length=20), nullable=False),
|
|
sa.Column('unit', sa.String(length=20), nullable=True),
|
|
sa.Column('spec_min', sa.Float(), nullable=True),
|
|
sa.Column('spec_max', sa.Float(), nullable=True),
|
|
sa.Column('warning_min', sa.Float(), nullable=True),
|
|
sa.Column('warning_max', sa.Float(), nullable=True),
|
|
sa.Column('trend_window', sa.Integer(), nullable=True),
|
|
sa.Column('select_options', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
|
|
sa.Column('equipment_part_id', sa.UUID(), nullable=True),
|
|
sa.Column('is_required', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(['equipment_part_id'], ['equipment_parts.id'], ),
|
|
sa.ForeignKeyConstraint(['template_id'], ['inspection_templates.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index('ix_template_items_template_order', 'inspection_template_items', ['template_id', 'sort_order'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index('ix_template_items_template_order', table_name='inspection_template_items')
|
|
op.drop_table('inspection_template_items')
|
|
op.drop_index('ix_templates_tenant_subject', table_name='inspection_templates')
|
|
op.drop_index('ix_templates_tenant_machine', table_name='inspection_templates')
|
|
op.drop_table('inspection_templates')
|
|
# ### end Alembic commands ###
|