161 lines
8.5 KiB
Python
161 lines
8.5 KiB
Python
"""p4_product_skill
|
|
|
|
Revision ID: 0b286bfebd6e
|
|
Revises: 7c8589fdbff1
|
|
Create Date: 2026-04-24 13:59:03.048452
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '0b286bfebd6e'
|
|
down_revision: str | Sequence[str] | None = '7c8589fdbff1'
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('channel_code',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('code', sa.String(length=64), nullable=False),
|
|
sa.Column('name', sa.String(length=64), nullable=False),
|
|
sa.Column('type', sa.String(length=16), nullable=False),
|
|
sa.Column('description', sa.String(length=255), nullable=True),
|
|
sa.Column('status', sa.String(length=16), 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('code')
|
|
)
|
|
op.create_table('platform',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('code', sa.String(length=64), nullable=False),
|
|
sa.Column('name', sa.String(length=64), nullable=False),
|
|
sa.Column('url', sa.String(length=255), nullable=True),
|
|
sa.Column('description', sa.String(length=255), nullable=True),
|
|
sa.Column('status', sa.String(length=16), 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('code')
|
|
)
|
|
op.create_table('product',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('code', sa.String(length=64), nullable=False),
|
|
sa.Column('name', sa.String(length=128), nullable=False),
|
|
sa.Column('platform_id', sa.Integer(), nullable=True),
|
|
sa.Column('dept_id', sa.Integer(), nullable=True),
|
|
sa.Column('owner_id', sa.Integer(), nullable=True),
|
|
sa.Column('description', sa.String(length=255), nullable=True),
|
|
sa.Column('status', sa.String(length=16), 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(['dept_id'], ['organization.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['platform_id'], ['platform.id'], ondelete='SET NULL'),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('code')
|
|
)
|
|
op.create_index(op.f('ix_product_dept_id'), 'product', ['dept_id'], unique=False)
|
|
op.create_index(op.f('ix_product_owner_id'), 'product', ['owner_id'], unique=False)
|
|
op.create_index(op.f('ix_product_platform_id'), 'product', ['platform_id'], unique=False)
|
|
op.create_table('script_template',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('code', sa.String(length=64), nullable=False),
|
|
sa.Column('name', sa.String(length=128), nullable=False),
|
|
sa.Column('language', sa.String(length=16), nullable=False),
|
|
sa.Column('description', sa.String(length=255), nullable=True),
|
|
sa.Column('content', sa.Text(), nullable=False),
|
|
sa.Column('version', sa.Integer(), nullable=False),
|
|
sa.Column('timeout_seconds', sa.Integer(), nullable=False),
|
|
sa.Column('status', sa.String(length=16), nullable=False),
|
|
sa.Column('owner_id', sa.Integer(), 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.ForeignKeyConstraint(['owner_id'], ['user.id'], ondelete='SET NULL'),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('code')
|
|
)
|
|
op.create_table('product_channel_code',
|
|
sa.Column('product_id', sa.Integer(), nullable=False),
|
|
sa.Column('channel_code_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['channel_code_id'], ['channel_code.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('product_id', 'channel_code_id')
|
|
)
|
|
op.create_table('skill',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('code', sa.String(length=64), nullable=False),
|
|
sa.Column('name', sa.String(length=128), nullable=False),
|
|
sa.Column('category', sa.String(length=32), nullable=True),
|
|
sa.Column('executor_type', sa.String(length=16), nullable=False),
|
|
sa.Column('description', sa.String(length=255), nullable=True),
|
|
sa.Column('input_schema', sa.JSON(), nullable=True),
|
|
sa.Column('param_mapping', sa.JSON(), nullable=True),
|
|
sa.Column('lobster_template_id', sa.String(length=128), nullable=True),
|
|
sa.Column('script_template_id', sa.Integer(), nullable=True),
|
|
sa.Column('status', sa.String(length=16), nullable=False),
|
|
sa.Column('doc', sa.Text(), 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.ForeignKeyConstraint(['script_template_id'], ['script_template.id'], ondelete='SET NULL'),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('code')
|
|
)
|
|
op.create_table('skill_call_log',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('skill_id', sa.Integer(), nullable=False),
|
|
sa.Column('skill_code', sa.String(length=64), nullable=False),
|
|
sa.Column('operator_id', sa.Integer(), nullable=True),
|
|
sa.Column('operator_name', sa.String(length=64), nullable=True),
|
|
sa.Column('executor_type', sa.String(length=16), nullable=False),
|
|
sa.Column('product_id', sa.Integer(), nullable=True),
|
|
sa.Column('input_data', sa.JSON(), nullable=True),
|
|
sa.Column('output_data', sa.JSON(), nullable=True),
|
|
sa.Column('result', sa.String(length=16), nullable=False),
|
|
sa.Column('message', sa.String(length=512), nullable=True),
|
|
sa.Column('cost_ms', sa.Integer(), nullable=False),
|
|
sa.Column('source', sa.String(length=16), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
|
sa.ForeignKeyConstraint(['operator_id'], ['user.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ondelete='SET NULL'),
|
|
sa.ForeignKeyConstraint(['skill_id'], ['skill.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_skill_call_log_created_at'), 'skill_call_log', ['created_at'], unique=False)
|
|
op.create_index(op.f('ix_skill_call_log_operator_id'), 'skill_call_log', ['operator_id'], unique=False)
|
|
op.create_index(op.f('ix_skill_call_log_skill_id'), 'skill_call_log', ['skill_id'], unique=False)
|
|
op.create_table('skill_product_scope',
|
|
sa.Column('skill_id', sa.Integer(), nullable=False),
|
|
sa.Column('product_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['product_id'], ['product.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['skill_id'], ['skill.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('skill_id', 'product_id')
|
|
)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_table('skill_product_scope')
|
|
op.drop_index(op.f('ix_skill_call_log_skill_id'), table_name='skill_call_log')
|
|
op.drop_index(op.f('ix_skill_call_log_operator_id'), table_name='skill_call_log')
|
|
op.drop_index(op.f('ix_skill_call_log_created_at'), table_name='skill_call_log')
|
|
op.drop_table('skill_call_log')
|
|
op.drop_table('skill')
|
|
op.drop_table('product_channel_code')
|
|
op.drop_table('script_template')
|
|
op.drop_index(op.f('ix_product_platform_id'), table_name='product')
|
|
op.drop_index(op.f('ix_product_owner_id'), table_name='product')
|
|
op.drop_index(op.f('ix_product_dept_id'), table_name='product')
|
|
op.drop_table('product')
|
|
op.drop_table('platform')
|
|
op.drop_table('channel_code')
|
|
# ### end Alembic commands ###
|