"""Phase 6.1 — enterprise CRM core entities schema expansion."""
from alembic import op
from app.core.database import Base
import app.models  # noqa: F401

revision = "0002_phase_61_entities"
down_revision = "0001_initial"
branch_labels = None
depends_on = None


def upgrade():
    bind = op.get_bind()
    Base.metadata.create_all(bind=bind)


def downgrade():
    # Additive phase — drop only new tables if rolling back in non-prod.
    tables = [
        "crm_audit",
        "crm_attachments",
        "crm_note_versions",
        "crm_notes",
        "crm_addresses",
        "crm_custom_field_values",
        "crm_custom_fields",
        "organization_tags",
        "contact_tags",
        "lead_tags",
        "crm_tags",
        "lead_assignments",
        "organization_industries",
        "organization_types",
        "contact_types",
        "lead_statuses",
        "lead_sources",
    ]
    for table in tables:
        op.drop_table(table)
