昔于第一篇,吾等尝观Dataform之CompilationResult与WorkflowInvocation二物。今续之,略览余若干API端点,吾以为用甚便。
作业空间之管理——delete_workspace与create_workspace
delete_workspace乃大团队所用Dataform实例之要,盖因其能使工作空间于合并后自动删除,免却每半年必发之“众可否告我,其已毕之工作空间为何?”之讯。此可融入CI/CD工具,如GitHub Actions中。
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)
复有create_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")












