"""Warranty plugin: warranties + warrantyassets

Revision ID: 7d15_warranties
Revises: 7d14_customfields
Create Date: 2026-07-09

"""
from alembic import op
import sqlalchemy as sa


revision = '7d15_warranties'
down_revision = '7d14_customfields'
branch_labels = None
depends_on = None


def upgrade():
    op.create_table(
        'warranties',
        sa.Column('warrantyid', sa.Integer(), primary_key=True),
        sa.Column('vendor', sa.String(length=100), nullable=False),
        sa.Column('servicetag', sa.String(length=100), nullable=True),
        sa.Column('provider', sa.String(length=20), nullable=False, server_default='manual'),
        sa.Column('servicelevel', sa.String(length=150), nullable=True),
        sa.Column('startdate', sa.Date(), nullable=True),
        sa.Column('enddate', sa.Date(), nullable=True),
        sa.Column('lastcheckeddate', sa.DateTime(), nullable=True),
        sa.Column('notes', sa.Text(), nullable=True),
        sa.Column('isactive', sa.Boolean(), nullable=False, server_default='1'),
    )
    op.create_table(
        'warrantyassets',
        sa.Column('id', sa.Integer(), primary_key=True),
        sa.Column('warrantyid', sa.Integer(), nullable=False),
        sa.Column('assetid', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['warrantyid'], ['warranties.warrantyid'], ondelete='CASCADE'),
        sa.ForeignKeyConstraint(['assetid'], ['assets.assetid'], ondelete='CASCADE'),
        sa.UniqueConstraint('warrantyid', 'assetid', name='uq_warrantyasset_warranty_asset'),
    )


def downgrade():
    op.drop_table('warrantyassets')
    op.drop_table('warranties')
