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.

📦 PyPI: https://pypi.org/project/dataform-view-migrator/ 💻 GitHub: https://github.com/elvainch/dataform-view-migrator

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

Install

pip install dataform-view-migrator

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.5.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.5-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for dataform_view_migrator-0.1.5.tar.gz
Algorithm Hash digest
SHA256 cb2da79636eb1718f1bb184736f2ea6bd4d16a9f168add800c306fa7fb661211
MD5 c68178386b6b7010e461a6bfb1f3d29d
BLAKE2b-256 7c611337e0268c7732f9351350bcae5e135551f40cb0be525a67802fb241107f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataform_view_migrator-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0d2d45728e9bba6a457383d4320189596e17edf6c40f67a76f7228487ae749
MD5 3b79ea614616def961dba5b38d2d2dba
BLAKE2b-256 1b5861d42fd19ed0abb778a66b4ff09ad55c000a9fad5cf67a981b2a50127df1

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