"""Drop bailian_applications table + bailian.application_sync job row. Why: the international ModelStudio control plane (the only one Helix targets — see ``app/domains/bailian/client.py``) has no ``ListApplications`` action. The previous implementation left a graceful no-op in place, but the user's production-grade rule forbids stub methods. We honour that by removing the dead surface: * the ``bailian_applications`` table — never populated against an intl tenant, no read path remains in the codebase * the ``bailian.application_sync`` row in ``scheduled_jobs`` — the worker would otherwise WARN "no registered handler" once per hour This is destructive: any rows that exist (none expected, since intl sync never produced any) are dropped. The downgrade re-creates the table shell (without data) and the scheduled-jobs row, so the schema shape can be restored if CN Bailian support ever lands. """ from __future__ import annotations import uuid import sqlalchemy as sa from alembic import op revision = "084" down_revision = "083" branch_labels = None depends_on = None _JOB_NAME = "bailian.application_sync" def upgrade() -> None: bind = op.get_bind() op.drop_table("bailian_applications") bind.execute( sa.text("DELETE FROM scheduled_jobs WHERE name = :name"), {"name": _JOB_NAME}, ) def downgrade() -> None: # Re-create the table shell so a downgrade restores the schema # without forcing the operator to hand-write DDL. The data is # gone forever — production never had any. op.create_table( "bailian_applications", sa.Column("id", sa.CHAR(36), primary_key=True), sa.Column( "workspace_pk", sa.CHAR(36), sa.ForeignKey("bailian_workspaces.id", ondelete="CASCADE"), nullable=False, ), sa.Column("application_id", sa.String(128), nullable=False), sa.Column("name", sa.String(256), nullable=False), sa.Column("description", sa.Text), sa.Column("application_type", sa.String(32)), sa.Column("model_name", sa.String(128)), sa.Column( "status", sa.String(32), nullable=False, server_default=sa.text("'active'"), ), sa.Column( "owner_person_id", sa.String(36), sa.ForeignKey("identity_persons.id", ondelete="SET NULL"), ), sa.Column("raw_data", sa.JSON), sa.Column( "first_seen_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now(), ), sa.Column( "last_synced_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now(), ), sa.Column("deleted_at", sa.DateTime(timezone=True)), sa.Column( "created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now(), ), sa.Column( "updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now(), ), sa.UniqueConstraint( "workspace_pk", "application_id", name="uq_bailian_app_workspace_appid", ), sa.Index( "ix_bailian_applications_workspace", "workspace_pk", ), ) bind = op.get_bind() bind.execute( sa.text( """ INSERT INTO scheduled_jobs (id, name, display_name, description, handler_key, trigger_type, interval_seconds, cron_expr, timezone, enabled, config, run_count, failure_count, created_at, updated_at) VALUES (:id, :name, :display_name, '', :name, 'cron', NULL, '30 4 * * *', 'UTC', 1, '{}', 0, 0, NOW(), NOW()) """ ), { "id": str(uuid.uuid4()), "name": _JOB_NAME, "display_name": "阿里云百炼应用同步", }, )