"""make config_schema nullable in source table

Revision ID: a3bd1bc10571
Revises: 75e709e9d355
Create Date: 2025-07-10 15:03:12.750977

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'a3bd1bc10571'
down_revision = '75e709e9d355'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('source', 'config_schema',
               existing_type=postgresql.JSON(astext_type=sa.Text()),
               nullable=True)
    op.drop_constraint(op.f('user_organization_organization_id_fkey'), 'user_organization', type_='foreignkey')
    op.drop_constraint(op.f('user_organization_user_id_fkey'), 'user_organization', type_='foreignkey')
    op.create_foreign_key(None, 'user_organization', 'user', ['user_id'], ['id'])
    op.create_foreign_key(None, 'user_organization', 'organization', ['organization_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'user_organization', type_='foreignkey')
    op.drop_constraint(None, 'user_organization', type_='foreignkey')
    op.create_foreign_key(op.f('user_organization_user_id_fkey'), 'user_organization', 'user', ['user_id'], ['id'], ondelete='CASCADE')
    op.create_foreign_key(op.f('user_organization_organization_id_fkey'), 'user_organization', 'organization', ['organization_id'], ['id'], ondelete='CASCADE')
    op.alter_column('source', 'config_schema',
               existing_type=postgresql.JSON(astext_type=sa.Text()),
               nullable=False)
    # ### end Alembic commands ###
