feat(api): migration to add custom_types table

This commit is contained in:
dextmorgn
2025-11-06 14:43:04 +01:00
parent 7e5fbb595f
commit bb08ba2bf9
@@ -0,0 +1,50 @@
"""add custom_types table
Revision ID: 8173aba964e7
Revises: 8d0e12b68d1e
Create Date: 2025-11-06 11:15:59.143311
"""
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 = '8173aba964e7'
down_revision: Union[str, None] = '8d0e12b68d1e'
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('custom_types',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.Text(), nullable=False),
sa.Column('owner_id', sa.UUID(), nullable=False),
sa.Column('schema', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
sa.Column('status', sa.String(), server_default='draft', nullable=False),
sa.Column('checksum', sa.String(), nullable=True),
sa.Column('description', sa.Text(), 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), server_default=sa.text('now()'), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['profiles.id'], onupdate='CASCADE', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_index('idx_custom_types_name', 'custom_types', ['name'], unique=False)
op.create_index('idx_custom_types_owner_id', 'custom_types', ['owner_id'], unique=False)
op.create_index('idx_custom_types_status', 'custom_types', ['status'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('idx_custom_types_status', table_name='custom_types')
op.drop_index('idx_custom_types_owner_id', table_name='custom_types')
op.drop_index('idx_custom_types_name', table_name='custom_types')
op.drop_table('custom_types')
# ### end Alembic commands ###