"""add_repo_commit_models

Revision ID: c80fc0e31e4a
Revises: fab0a53299d6
Create Date: 2026-03-20 00:14:47.622498

"""
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 = 'c80fc0e31e4a'
down_revision: Union[str, None] = 'fab0a53299d6'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('repos',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('repo_slug', sa.String(length=255), nullable=True),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('user_id', sa.UUID(), nullable=False),
    sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('repo_slug')
    )
    op.create_index(op.f('ix_repos_user_id'), 'repos', ['user_id'], unique=False)
    op.create_table('commits',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('repo_id', sa.UUID(), nullable=False),
    sa.Column('commit_hash', sa.String(length=64), nullable=False),
    sa.Column('parent_commit_id', sa.UUID(), nullable=True),
    sa.Column('branch_name', sa.String(length=255), nullable=False),
    sa.Column('author_agent', sa.String(length=255), nullable=True),
    sa.Column('author_type', sa.String(length=50), nullable=False),
    sa.Column('message', sa.String(length=255), nullable=False),
    sa.Column('summary', sa.Text(), nullable=False),
    sa.Column('objective', sa.Text(), nullable=False),
    sa.Column('decisions', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('tasks', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('open_questions', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('entities', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('context_blob', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('raw_source_text', sa.Text(), nullable=True),
    sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['parent_commit_id'], ['commits.id'], ondelete='SET NULL'),
    sa.ForeignKeyConstraint(['repo_id'], ['repos.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('commit_hash')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('commits')
    op.drop_index(op.f('ix_repos_user_id'), table_name='repos')
    op.drop_table('repos')
    # ### end Alembic commands ###
