Skip to main content

Helps migrating database schema changes using pydal.

Project description

Educationwarehouse's Migrate

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pip install edwh-migrate
# or to include extra dependencies (psycopg2, redis):
pip install edwh-migrate[full]

Documentation

Config: Environment variables

These variables can be set in the current environment or via .env:

  • MIGRATE_URI (required): regular postgres://user:password@host:port/database or sqlite:///path/to/database URI
  • DATABASE_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 to ewh_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 to public.
  • USE_TYPEDAL: pass a TypeDAL instance to migrations instead of a regular pyDAL.

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


Download files

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

Source Distribution

edwh_migrate-0.9.6.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

edwh_migrate-0.9.6-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file edwh_migrate-0.9.6.tar.gz.

File metadata

  • Download URL: edwh_migrate-0.9.6.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for edwh_migrate-0.9.6.tar.gz
Algorithm Hash digest
SHA256 91cb263161a4c0ad2ae522c9b1814f2ae792e40f523f160ad6c4ad1b9f1bb3e8
MD5 e0c087c8bcf55052e90d5650de0c97b7
BLAKE2b-256 691662a2515fd52715072c95e31c54c886c8cd8253c0998873cd1caf54aa3742

See more details on using hashes here.

File details

Details for the file edwh_migrate-0.9.6-py3-none-any.whl.

File metadata

File hashes

Hashes for edwh_migrate-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0102d4c3ae6f198dae26fcb27d971266e788361c1aa5124544935ead74ffaa68
MD5 0a952050adfa7e8caee64cca2996023f
BLAKE2b-256 feec412c9e705a69948309aba192bc5281c540c111b6dd3431a22715e1d431cc

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