Skip to main content

A data migration tool (GCP, BigQuery)

Project description

dmt (Data migration tool)

Note: has been thought for GCP / BigQuery.

Why this tool?

Most data transformation tools (dataform, dbt) have schema-on-read features. In other words, you don't have to take care of the schema migration. This is enough 98% of the time.

The main use case of this tool is to provide a framework to handle the remaining 2% of use cases when you want to automate the migration of your schemas:

  • source tables
  • big data tables

Handle any BigQuery resource

This tool can/should only impact resources with a lifecycle (create, update, delete) that can be managed in SQL, such as:

  • views
  • user defined functions (udfs)

How to create a new BigQuery migration?

  • Create a python file in a migrations directory
  • The file should be named following the convention XXXX_my_migration_name.py
  • Write a migrate and a rollback function

This tool does not replace terraform

Note that you can use this tool to execute any side effect on your data and cloud resources that can be executed in python thanks to the google cloud SDK.

That being said, we strongly recommend to manage your infrastructure resources with terraform.

How to execute a migration?

Executing a migration

PYTHONPATH=/PATH/TO/migrations dmt XXXX_my_migration_name.py

Rolling back

PYTHONPATH=/PATH/TO/migrations dmt XXXX_my_migration_name.py --rollback

Before executing

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Runtime relies on application default credentials.

gcloud auth application-default login

Configure the project:

gcloud config set project my-gcp-project

or

export GOOGLE_CLOUD_PROJECT=my-gcp-project

Limitations

Ideally this tool should support:

  • Resolving the linked list of migration versions at runtime to understand that one migration comes after another one
  • Executing multiple migrations versions from a single execution command
  • Remembering the migration version by storing it in a database
  • Reading the latest known version to understand all subsequent migrations to execute + execute them
  • Proposing helper functions (rename_table, rename_column, remove_column, add_column, etc.) to generate migration and rollback SQL code
  • Automatically executing BEGIN TRANSACTION, COMMIT TRANSACTION and ROLLBACK TRANSATION statements before / after executing the migrate and rollback functions. This would open the possibility to add a --dry-run flag, which would be convenient during development cycles.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

data_migration_tool-0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

data_migration_tool-0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file data_migration_tool-0.1.tar.gz.

File metadata

  • Download URL: data_migration_tool-0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for data_migration_tool-0.1.tar.gz
Algorithm Hash digest
SHA256 a7a98fdfb76b19068cdde11e70000abd1b61edb2a8d4d352cdf97cfc513adfe9
MD5 b7aee119a9ce882f029654e8f30b8fac
BLAKE2b-256 a45221f33ec6987c94c7980fa05136291a8da09c697ce0c41d8b98b30e47c317

See more details on using hashes here.

File details

Details for the file data_migration_tool-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for data_migration_tool-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2373b20dab3ab99b9359255163ec3900586fb23cc8ca965f886b5832fbddfb20
MD5 78a8a0fd567067fce4f54e78ac017d9f
BLAKE2b-256 8774aa04cf8396114cf79d3883f0694f12092b4d12078cd541941e2eb8e43e4b

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