Migration library for Clickhouse
Project description
ClickHouse Migrate
Python library for applying migrations in ClickHouse database.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clickhouse-migrate-0.0.1b0.tar.gz
.
File metadata
- Download URL: clickhouse-migrate-0.0.1b0.tar.gz
- Upload date:
- Size: 8.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b75280c2a45e85cb58970b9207add7a4b7b6fc75fd3f3017b30fbc1cf42e282 |
|
MD5 | f5df1c946496dc8e2156420750c2811f |
|
BLAKE2b-256 | 4ba230e14d896ad1aaa29f0c0fcf13216e756331f0967527143f0f4bf4718591 |
File details
Details for the file clickhouse_migrate-0.0.1b0-py3-none-any.whl
.
File metadata
- Download URL: clickhouse_migrate-0.0.1b0-py3-none-any.whl
- Upload date:
- Size: 11.5 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 655af7d0563c3cffd94b5319ed793144eb6c106c08e9c887f50a7a266bca0029 |
|
MD5 | f37350fa985279f1ff38a9900e1d08b5 |
|
BLAKE2b-256 | 77832659983ddf3af7b144a203d8d1477678b3d54c859da6c74f835b16ab33c6 |