Helps migrating database schema changes using pydal.
Project description
Educationwarehouse's Migrate
Table of Contents
Installation
pip install edwh-migrate
Documentation
Config: Environment variables
These variables can be set in the current environment or via .env
:
MIGRATE_URI
(required): regularpostgres://user:password@host:port/database
orsqlite:///path/to/database
URIDATABASE_TO_RESTORE
: path to a (compressed) SQL file to restore..xz
,.gz
and.sql
are supported.MIGRATE_CAT_COMMAND
: for unsupported compression formats, this command decompresses the file and produces sql on the stdout.SCHEMA_VERSION
: Used in case of schema versioning. Set by another process.REDIS_HOST
: If set, all keys of the redis database 0 will be removed.MIGRATE_TABLE
: name of the table where installed migrations are stored. Defaults toewh_implemented_features
.FLAG_LOCATION
: when using schema versioned lock files, this directory is used to store the flags. Defaults to/flags
.CREATE_FLAG_LOCATION
(bool): should the directory above be created if it does not exist yet? Defaults to 0 (false).SCHEMA
: (for postgres) set the default namespace (search_path
). Defaults topublic
.
Config: pyproject.toml
You can also set your config variables via the [tool.migrate]
key in pyproject.toml
.
First, these variables are loaded and then updated with variables from the environment.
This way, you can set static variables (the ones you want in git, e.g. the migrate_table
name or path to the backup to
restore) in the toml, and keep private/dynamic vars in the environment (e.g. the database uri or schema version).
Example:
[tool.migrate]
migrate_uri = "" # filled in by .env
database-to-restore = "migrate/data/db_backup.sql"
# ...
Creating a migrations.py
from edwh_migrate import migration
@migration
def feature_1(db):
print("feature_1")
return True
@migration(requires=[feature_1]) # optional `requires` ensures previous migration(s) are installed
def functionalname_date_sequencenr(db: pydal.DAL):
db.executesql("""
CREATE TABLE ...
""")
db.commit()
return True
Usage
When your configuration is set up properly and you have a file containing your migrations, you can simply run:
migrate
# or, to use a different name than migrations.py:
migrate path/to/my/migrate_file.py
License
edwh-migrate
is distributed under the terms of the MIT license.
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 edwh_migrate-0.6.1.tar.gz
.
File metadata
- Download URL: edwh_migrate-0.6.1.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36e926016e32390b34038aeb13c7875a182368398e3552643fe07713aac81a34 |
|
MD5 | 3ca0d9bf412aa4c3e598490f15c4c60f |
|
BLAKE2b-256 | f6fa96be4d9761fa6d5b0341d1886a077c8d54b373368d695a7a9892a5533c28 |
File details
Details for the file edwh_migrate-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: edwh_migrate-0.6.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5da1338aa6008e29847d4acf28a1e3dcb51a4a29f32f5d7b3b680bef56d66f9 |
|
MD5 | 806e77fab6f370dcdf37b0249590d537 |
|
BLAKE2b-256 | e05ba26e676c5783de4d745836f06989ff8525aa98ea0ed5a1df5fdd812aa30a |