第1部では、DataformのCompilationResultとWorkflowInvocationオブジェクトを見ました。私が便利だと思う他のいくつかのAPIエンドポイントについて、簡単に見ていきましょう
。
ワークスペース管理 - delete_workspaceとcreate_workspace
delete_workspace は大規模なチームで使用される Dataform インスタンスにとって不可欠です。なぜなら、マージ後にワークスペースを自動的に削除できるため、半年ごとの「どのワークスペースが終了したか教えてください」というメッセージを節約できるからです。これは GitHub Actions のような CI/CD ツールに統合できます。
from google.cloud import dataform_v1
client = dataform_v1.DataformClient()
workspace_path = client.workspace_path(
PROJECT_ID,
REGION,
REPOSITORY_ID,
WORKSPACE_ID,
)
try:
operation = client.delete_workspace(name=workspace_path)
There's alsocreate_workspace - 新しいブランチでDataform UIの外側でコード変更が行われた場合にワークスペースを自動的に作成するのに非常に便利です.
Git操作 - push_git_changesとpull_git_changes
Dataform UIの外側でコード変更を自動的に適用できる便利なエンドポイントのセットです.
from google.cloud import dataform_v1
client = dataform_v1.DataformClient()
workspace_path = client.workspace_path(
project_id,
region,
repository_id,
workspace_id,
)
# ------------------------------------------------------------
# 1. Pull latest changes from Git into the workspace
# ------------------------------------------------------------
print("Pulling latest Git changes into workspace...")
pull_request = dataform_v1.PullGitChangesRequest(
name=workspace_path
)
pull_operation = client.pull_git_changes(request=pull_request)
print("Pull initiated:", pull_operation.operation.name)
# Optional: wait for completion (simplified polling)
pull_result = pull_operation.result()
print("Pull completed successfully")
# ------------------------------------------------------------
# (Optional) 2. Make programmatic changes here
# ------------------------------------------------------------
# e.g. update config blocks, inject variables, generate models, format SQL, etc.
print("Applying automated workspace changes...")
# ------------------------------------------------------------
# 3. Push workspace changes back to Git
# ------------------------------------------------------------
print("Pushing workspace changes to Git...")
push_request = dataform_v1.PushGitChangesRequest(
name=workspace_path
)
push_operation = client.push_git_changes(request=push_request)
push_result = push_operation.result()
print("Push completed successfully")
print("Workspace successfully synced with Git")












