"""Add natively null org and user columns to connection table

Revision ID: 97758b0549eb
Revises: f7ca978e503b
Create Date: 2025-03-12 14:39:09.572662

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '97758b0549eb'
down_revision = 'f7ca978e503b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('connection', 'organization_id',
               existing_type=sa.UUID(),
               nullable=True)
    op.alter_column('connection', 'created_by_email',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.alter_column('connection', 'modified_by_email',
               existing_type=sa.VARCHAR(),
               nullable=True)
    op.drop_constraint('connection_created_by_email_fkey', 'connection', type_='foreignkey')
    op.drop_constraint('connection_modified_by_email_fkey', 'connection', type_='foreignkey')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_foreign_key('connection_modified_by_email_fkey', 'connection', 'user', ['modified_by_email'], ['email'])
    op.create_foreign_key('connection_created_by_email_fkey', 'connection', 'user', ['created_by_email'], ['email'])
    op.alter_column('connection', 'modified_by_email',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.alter_column('connection', 'created_by_email',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.alter_column('connection', 'organization_id',
               existing_type=sa.UUID(),
               nullable=False)
    # ### end Alembic commands ###
