"""add_relationships_between_tables

Revision ID: 1fad074c433a
Revises: 0512c4b5a1ed
Create Date: 2025-09-04 05:21:51.490096

"""
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 = '1fad074c433a'
down_revision: Union[str, None] = '0512c4b5a1ed'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
# In your migration file (1fad074c433a_add_relationships_between_tables.py)
from alembic import op
import sqlalchemy as sa

def upgrade():
    # # Check if constraints exist before creating them
    # conn = op.get_bind()
    
    # # Check if fk_subscription_company exists
    # result = conn.execute(
    #     "SELECT 1 FROM pg_constraint WHERE conname = 'fk_subscription_company'"
    # ).scalar()
    
    # if not result:
    #     op.create_foreign_key(
    #         'fk_subscription_company',
    #         'subscriptions',
    #         'companies',
    #         ['company_id'],
    #         ['id']
    #     )
    
    # # Check if fk_subscription_plan exists
    # result = conn.execute(
    #     "SELECT 1 FROM pg_constraint WHERE conname = 'fk_subscription_plan'"
    # ).scalar()
    
    # if not result:
    #     op.create_foreign_key(
    #         'fk_subscription_plan',
    #         'subscriptions',
    #         'subscription_plans',
    #         ['plan_id'],
    #         ['subscription_plan_id']
    #     )
    pass

def downgrade():
    # Safely drop constraints if they exist
    op.drop_constraint('fk_subscription_plan', 'subscriptions', type_='foreignkey', if_exists=True)
    op.drop_constraint('fk_subscription_company', 'subscriptions', type_='foreignkey', if_exists=True)