Skip to main content

Migration library for Clickhouse

Project description

ClickHouse Migrate

codecov PyPI version

Python library for applying migrations in ClickHouse database.

Installation

Installation via PyPi:

pip install clickhouse-migrate

Configuration

To configure and clickhouse-migrate we can create a *.ini configuration file with the following content

[databases]
# Here we should provide a connection string to a database
# In case of using a replicated ClickHouse instance one should provide all connection strings
# related to this particular replicated instance
connection_strings = [
        "clickhouse+native://default:@localhost:9000/clickhouse_migrate"
    ]

[migration_path]
# Here we should provide a path to the selected migration folder
directory = "./migrations"

Default name that is used by clickhouse-migrate library is clickhouse_migrate.ini Configurator will search for this file by default.

Usage

Create migration file

One can create a new migration via calling clickhouse-migrate create_migration command.

Command parameters:

--name <name of a new migration file> — this is a required parameter

--config <path to the created config file> — this is an optional parameter, one may want to use it when the config file is not located in the root directory or if its' name is different from default one

After calling the above-mentioned command a blank migration file YYYY-MM-DD-HH-mm-ss_<migration_name>.py will be created in the directory which was defined in the *.ini configuration file.

The content of the created file will look like this

from clickhouse_migrate import Step

migrations = [Step(sql="")]

One should use Step dataclass to create migrations. Migrations would be applied in the same order that they are stated in the migrations list variable. All of listed changes in the migration list variable are by default applied to all databases listed in the *.ini config file, since usually changes are required for all replicated instances.

If an SQL query stated in the Step dataclass should not be executed for all DB replicas one may use Step(sql="<sql query>", replicated=False) statement.

This rule does not apply in case there is only one connection string in *.ini file.

Apply migrations

One can apply migrations created via clickhouse-migrate create_migration command by calling clickhouse-migrate migrate.

Command parameters:

--config <path to the created config file> — this is an optional parameter, one may want to use it when the config file is not located in the root directory or if its' name is different from default one

After calling this command all changes from migration files will be applied step-by-step. Changes are stored in clickhouse_migrate table.

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-migrate-0.0.2.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

clickhouse_migrate-0.0.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file clickhouse-migrate-0.0.2.tar.gz.

File metadata

  • Download URL: clickhouse-migrate-0.0.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for clickhouse-migrate-0.0.2.tar.gz
Algorithm Hash digest
SHA256 54c266949030f1a9f035057743294fcad91e2352250363eaf7a997cc52cc4997
MD5 cfd3ec8ea644156f990f3e509c64b668
BLAKE2b-256 72b9bf6fcf2dbe6c53da116abb8c3f365ba943b1daf4aac8854e6270675f9a4b

See more details on using hashes here.

File details

Details for the file clickhouse_migrate-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: clickhouse_migrate-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for clickhouse_migrate-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74ad9957c0a7401cb9f2dca2c76b5026b11adb3c5976ad0e3c3a37972cb5c6f2
MD5 4b127b1a27e6bd085329477d271d908c
BLAKE2b-256 e991694b0f88daeb379191d2791aaf0ca1160a8bc4bbbfd2cd425edf753cc4ee

See more details on using hashes here.

Supported by

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