删除迁移工作流

从 BigQuery Migration Service 项目中删除指定的迁移工作流。工作流不得处于正在运行的状态。

代码示例

Node.js

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 BigQuery Node.js API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

const {MigrationServiceClient} = require('@google-cloud/bigquery-migration').v2;
const {status} = require('@grpc/grpc-js');

const client = new MigrationServiceClient();

/**
 * Deletes a migration workflow by name.
 *
 * This is useful to clean up migration resources that are no longer needed.
 *
 * @param {string} projectId The Google Cloud project ID.
 * @param {string} location The workflow's location (for example, 'us').
 * @param {string} workflowId The ID of the migration workflow to delete (for example, '12345678-abcd-4372-a567-0e02b2c3d479').
 */
async function deleteMigrationWorkflow(
  projectId,
  location = 'us',
  workflowId = '12345678-abcd-4372-a567-0e02b2c3d479',
) {
  const name = client.migrationWorkflowPath(projectId, location, workflowId);

  const request = {
    name,
  };

  try {
    await client.deleteMigrationWorkflow(request);
    console.log(`Migration workflow ${workflowId} deleted successfully.`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Migration workflow ${workflowId} not found.`);
    } else {
      console.error(
        'An error occurred while deleting the migration workflow:',
        err,
      );
    }
  }
}

Python

试用此示例之前,请按照 BigQuery 快速入门:使用客户端库中的 Python 设置说明进行操作。 如需了解详情,请参阅 BigQuery Python API 参考文档

如需向 BigQuery 进行身份验证,请设置应用默认凭证。如需了解详情,请参阅为客户端库设置身份验证

from google.api_core import exceptions
from google.cloud import bigquery_migration_v2

client = bigquery_migration_v2.MigrationServiceClient()


def delete_migration_workflow(project_id: str, location: str, workflow_id: str) -> None:
    """Deletes a migration workflow.

    The migration workflow is a top-level resource that contains all the
    details about a migration. Deleting it will also delete all its
    sub-resources, such as migration tasks.

    Args:
        project_id: The Google Cloud project ID.
        location: The location of the migration workflow, for example, "us".
        workflow_id: The ID of the migration workflow to delete.
    """
    name = client.migration_workflow_path(project_id, location, workflow_id)

    try:
        client.delete_migration_workflow(name=name)
        print(f"Deleted migration workflow: {name}")
    except exceptions.NotFound:
        print(f"Migration workflow not found: {name}")

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器