Skip to main content

Simple file-based migrations for clickhouse

Project description

ci release PyPI version supported versions downloads my site

Clickhouse Migrations

Python library for creating and applying migrations in ClickHouse database.

Development and Maintenance of large-scale db systems many times requires constant changes to the actual DB system. Holding off the scripts to migrate these will be painful.

Features:

  • Supports multi statements - more than one query per migration file.
  • Allow running migrations out-of-box
  • Simple file migrations format: {VERSION}_{name}.sql
  • Supports Cluster deployments, makes sure that migrations state is consistent on all cluster nodes

Known alternatives

This package originally forked from clickhouse-migrator.

Package Differences
clickhouse-migrator Doesn't support multistatement in a single file , to heavy because of pandas, looks like abandoned
django-clickhouse Need django
clickhouse-migrate Doesn't support multistatement

Installation

You can install from pypi using pip install clickhouse-migrations.

Usage

In command line

clickhouse-migrations --db-host localhost \
    --db-user default \
    --db-password secret \
    --db-name test \
    --migrations-dir ./migrations

In code

from clickhouse_migrations.clickhouse_cluster import ClickhouseCluster

cluster = ClickhouseCluster(db_host, db_user, db_password)
cluster.migrate(db_name, migrations_home, cluster_name=None,create_db_if_no_exists=True, multi_statement=True)
Parameter Description Default
db_host Clickhouse database hostname localhost
db_port Clickhouse database port 9000
db_user Clickhouse user default
db_password Clichouse password default
db_name Clickhouse database name None
migration_path Path to list of migration files <project_root>
migrations Explicit list of migrations to apply []
cluster_name Name of Clickhouse topology cluster from <remote_servers> None
create_db_if_no_exists If the db_name is not present, enabling this will create the db True
multi_statement Allow multiple statements in migration files True
secure Use secure connection False
fake Marks the migrations as applied but without actually running the SQL to change your database schema False

Notes

The Clickhouse driver does not natively support executing multipe statements in a single query. To allow for multiple statements in a single migration, you can use the multi_statement param. There are two important caveats:

  • This mode splits the migration text into separately-executed statements by a semi-colon ;. Thus cannot be used when a statement in the migration contains a string with a semi-colon.
  • The queries are not executed in any sort of transaction/batch, meaning you are responsible for fixing partial migrations.

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

clickhouse_migrations-0.9.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

clickhouse_migrations-0.9.1-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file clickhouse_migrations-0.9.1.tar.gz.

File metadata

  • Download URL: clickhouse_migrations-0.9.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for clickhouse_migrations-0.9.1.tar.gz
Algorithm Hash digest
SHA256 ec24a66e7ff69a549be1cffe641c7856d218f55665ead654764e18dee4e96c48
MD5 8d1e466463960a5d92cf7058104525f1
BLAKE2b-256 3b4992a7706ac273e33d236e2ca431a1fa680e38124e7518c43d844e145f2808

See more details on using hashes here.

File details

Details for the file clickhouse_migrations-0.9.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for clickhouse_migrations-0.9.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e06ecac30e0f7cd82eb1e0f913fe2a746dc494484ea9ee3a30a7f51ae2d846b3
MD5 1067e68a7dc189c9e0fd1b55b35b99a3
BLAKE2b-256 f5958ac89636e1dce89f2beac1909439eb7b408e4ca1315fed08234e5d629a71

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