"""Add sync_connection table

Revision ID: f7ca978e503b
Revises: 86c0732b1e07
Create Date: 2025-03-12 14:04:05.206158

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'f7ca978e503b'
down_revision = '86c0732b1e07'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('sync_connection',
    sa.Column('sync_id', sa.UUID(), nullable=False),
    sa.Column('connection_id', sa.UUID(), nullable=False),
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('modified_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['connection_id'], ['connection.id'], ),
    sa.ForeignKeyConstraint(['sync_id'], ['sync.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_constraint('sync_embedding_model_connection_id_fkey', 'sync', type_='foreignkey')
    op.drop_constraint('sync_source_connection_id_fkey', 'sync', type_='foreignkey')
    op.drop_constraint('sync_destination_connection_id_fkey', 'sync', type_='foreignkey')
    op.drop_column('sync', 'destination_connection_id')
    op.drop_column('sync', 'source_connection_id')
    op.drop_column('sync', 'embedding_model_connection_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('sync', sa.Column('embedding_model_connection_id', sa.UUID(), autoincrement=False, nullable=True))
    op.add_column('sync', sa.Column('source_connection_id', sa.UUID(), autoincrement=False, nullable=False))
    op.add_column('sync', sa.Column('destination_connection_id', sa.UUID(), autoincrement=False, nullable=True))
    op.create_foreign_key('sync_destination_connection_id_fkey', 'sync', 'connection', ['destination_connection_id'], ['id'])
    op.create_foreign_key('sync_source_connection_id_fkey', 'sync', 'connection', ['source_connection_id'], ['id'])
    op.create_foreign_key('sync_embedding_model_connection_id_fkey', 'sync', 'connection', ['embedding_model_connection_id'], ['id'])
    op.drop_table('sync_connection')
    # ### end Alembic commands ###
