Skip to main content

Migrate BigQuery views into Dataform view definitions.

Project description

dataform-view-migrator

Export BigQuery VIEW SQL definitions into a Dataform project with a predictable layout and safe write policies.

This README focuses on using the tool. For development setup and project conventions, see DEVELOPMENT.md.

Prerequisites

  • Python 3.10+
  • Auth via Application Default Credentials (ADC):
    • Set GOOGLE_APPLICATION_CREDENTIALS to a service account JSON, or
    • Run gcloud auth application-default login
  • Optional: uv to run without manually activating a venv

Install

  • With uv (recommended): uv sync
  • Or use your existing Python 3.10+ environment and install deps from pyproject.toml

Commands

  • dataform-view-migrator (or python -m dataform_view_migrator): prints quick usage and version
  • dataform-view-migrator ping-bq [--project <id>] [--location <REGION>] [--config <toml>]
    • Verifies auth and prints the resolved BigQuery project. If --location is provided (or set in TOML), it performs a regional INFORMATION_SCHEMA dry-run; otherwise it lists datasets to verify access.
  • dataform-view-migrator migrate-views [options]
    • Discovers BigQuery views and writes files into the Dataform repo path.

Run --help on any command for complete options.

Configuration

  • Copy dataform_view_migrator.example.toml to dataform_view_migrator.toml and edit.
  • CLI flags override TOML values when explicitly provided.

Key options (flag → TOML):

  • --source-projectsource_project (required via config or flag)
  • --dest <path>dest (required via config or flag)
  • --datasets a,bdatasets_include = ["a","b"]
  • --exclude-datasets x,ydatasets_exclude = ["x","y"]
  • --location USlocation = "US"
  • --ext sql|sqlxext = "sqlx" (default sqlx)
  • --overwrite skip|backup|forceoverwrite = "skip" (default skip)
  • --add-dataform-header/--no-add-dataform-headeradd_dataform_header = true|false
  • --dry-run/--no-dry-rundry_run = false
  • Optional dataset folder remapping: dataset_folders = { src = "src_views" }

Output Layout

  • Files are written under dest/<dataset>/<view_name>.<ext> by default.
  • Use dataset_folders in TOML to map dataset names to custom subfolders.
  • Extension ext is sqlx by default; set --ext sql for plain SQL files.

Dataform Header (optional)

When enabled, each file is prefixed with a Dataform config block:

config {
  type: "view",
  schema: "<dataset>",
  name: "<view>"
  # optional fields below when configured
  # description: "...",
  # tags: ["..."]
}

Control via --add-dataform-header (or add_dataform_header = true). Customize with dataform_header.description and dataform_header.tags in TOML.

Overwrite Policy

  • skip (default): do not modify existing files; they are reported as skipped.
  • backup: if a file exists, move it to <name>.<ext>.bak[.N] and write the new content.
  • force: overwrite files in place.

All modes support --dry-run to preview actions as would-create, would-update, or would-skip without writing.

Examples

  • Verify auth/project using TOML defaults:
    • uv run dataform-view-migrator ping-bq --config dataform_view_migrator.toml
  • Migrate all views to a Dataform repo (US region, backup existing):
    • uv run dataform-view-migrator migrate-views --source-project my-proj --dest ../dataform --location US --overwrite backup
  • Include specific datasets and emit plain SQL:
    • uv run dataform-view-migrator migrate-views --source-project my-proj --dest ../dataform --datasets sales,finance --ext sql
  • Dry-run to review changes only:
    • uv run dataform-view-migrator migrate-views --config dataform_view_migrator.toml --dry-run

Output Report

After migration, a table of per-view results is printed (dataset, view, action, path, error) followed by a compact summary grouped by action. A non-zero exit code is returned if any views fail.

Development

See DEVELOPMENT.md for environment setup, linting/formatting, tests, and project layout.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataform_view_migrator-0.1.4.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dataform_view_migrator-0.1.4-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file dataform_view_migrator-0.1.4.tar.gz.

File metadata

File hashes

Hashes for dataform_view_migrator-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b69bb41f62434328f469219748dea7095393943642166dbd6527d6cb84247ba4
MD5 d0b48596612de7919653589d2a7f3fa9
BLAKE2b-256 810bc03f962296d442b7d84074bc09e7b1efdd5c02f0f5e8e9ed5ece336196cd

See more details on using hashes here.

File details

Details for the file dataform_view_migrator-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for dataform_view_migrator-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 07f661f35bab0a307890bae3b267c3c33187d4919b3bcd2c7b7557b6e4307a86
MD5 2c843b3a7eadde95b31de43953b2fa5d
BLAKE2b-256 b39f39fa7f84dfab709d3900ec1b92354f160b1215da349595de5be5ed244fc9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page