- Configure Alembic for async migrations with SQLAlchemy 2.0 - Create Build model with UUID primary key, config_hash, status enum - Add indexes on status (queue queries) and config_hash (cache lookups) - Generate and apply initial migration creating builds table Build model fields: id, config_hash, status, iso_path, error_message, build_log, started_at, completed_at, created_at, updated_at.
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""Create build table
|
|
|
|
Revision ID: de1460a760b0
|
|
Revises:
|
|
Create Date: 2026-01-25 20:11:11.446731
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'de1460a760b0'
|
|
down_revision: Union[str, Sequence[str], None] = None
|
|
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('builds',
|
|
sa.Column('id', sa.UUID(), nullable=False),
|
|
sa.Column('config_hash', sa.String(length=64), nullable=False),
|
|
sa.Column('status', sa.Enum('PENDING', 'BUILDING', 'COMPLETED', 'FAILED', 'CACHED', name='buildstatus'), nullable=False),
|
|
sa.Column('iso_path', sa.String(length=512), nullable=True),
|
|
sa.Column('error_message', sa.Text(), nullable=True),
|
|
sa.Column('build_log', sa.Text(), nullable=True),
|
|
sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('completed_at', sa.DateTime(timezone=True), 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.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_builds_config_hash'), 'builds', ['config_hash'], unique=True)
|
|
op.create_index('ix_builds_status', 'builds', ['status'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index('ix_builds_status', table_name='builds')
|
|
op.drop_index(op.f('ix_builds_config_hash'), table_name='builds')
|
|
op.drop_table('builds')
|
|
# ### end Alembic commands ###
|