Skip to main content

No project description provided

Project description

Flux Migrations

codecov

flux is a database migration tool written in Python and built with Python projects in mind.

N.B. this project is in a pre-release state. There may be breaking changes to all aspects of the tool while some decisions are being made and changed. It is not recommended for use in real projects until the v1.0.0 release. See (TODO milestone) for more info.

Adding flux to your project

CLI

flux can be installed for now from Github. For example:

poetry add git+https://github.com/k2bd/flux-migrations.git[postgres]

The project will be properly maintained on PyPI when it's stable. The PyPI version may therefore not be up-to-date at this time.

flux commands can then be listed with flux --help

For example, migrations can be initialized and started with:

flux init postgres

flux new "Initial migration"

Docker

(TODO)

Writing migrations

Use as a library

flux can be used as a library in your Python project to manage migrations programmatically. This can be particularly useful for testing.

Database backends

flux is a generic migration tool that can be adapted for use in many databases. It does this by having an abstract backend specification that can be implemented for any target database. Backends can also have their own configuration options.

Inbuilt backends

Postgres

flux comes packages with a Postgres backend. It maintains information about migrations in a configurable schema and table. Additionally, it uses an advisory lock while migrations are being applied with a configurable index. The available [backend] configs are:

  • migrations_schema
    • The schema in which to put the migration history table
    • (default "public")
  • migrations_table (default "_flux_migrations")
    • The table used for applied migration history
  • migrations_lock_id (default 3589 ('flux' on a phone keypad))
    • The pg_advisory_lock ID to use while applying migrations

Adding a new backend

Backends are loaded as plugins through Python's entry point system. This means that you can add a new backend by simply installing a package that provides the backend as a plugin.

To create a new backend in your package, you need to subclass flux.MigrationBackend and implement its abstract methods. Then register that class under the flux.backend entry point group in your package setup.

For example, in pyproject.toml:

[project.entry-points."flux.backend"]
cooldb = "my_package.my_module:CoolDbBackend"

Once the package is installed, the backend will be available to use with a flux, as long as it's installed in the same environment. An example configuration file for our new backend:

[flux]
backend = "cooldb"
migration_directory = "migrations"

[backend]
coolness_level = 11
another_option = "cool_value"

Why flux?

I have used a number of migration frameworks for databases that sit behind Python projects. I've liked some features of different projects but the complete feature-set I'd like to use in my work has never been in one project.

A non-exhaustive list of this feature-set includes

  • very flexible support for repeatable migration scripts
  • migration directory corruption detection
  • the ability to easily leverage Python to reuse code in migrations
  • a Python library to easily manage migrations programmatically for test writing (e.g. integration tests of the effects of individual migrations)

So, the motivation for this project was to

  • present a more complete feature-set you'd want to find in a migration framework for use with Python projects
  • use design patterns that make it easy to adapt for different kinds of projects, such as
    • the plugin-based backend system
    • the co-maintenance of official Docker images

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

flux_migrations-0.0.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

flux_migrations-0.0.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file flux_migrations-0.0.1.tar.gz.

File metadata

  • Download URL: flux_migrations-0.0.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for flux_migrations-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c417d3d9665acbfade5c21c6225350333c1a3d523c9880197f2866558bb562e4
MD5 6d78efd0547e9b05228dbbbeef86e6b6
BLAKE2b-256 eff4031425df6cf2a986237471890fab5250797eb7c7f7c3d3c96ee9c269573f

See more details on using hashes here.

File details

Details for the file flux_migrations-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: flux_migrations-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for flux_migrations-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11c7926c095f13f7c57456e92e4c8aef580b64f49236acbd146e7d01d6fb56f7
MD5 1c0d138a2ecab310c7640f8e36bd3a15
BLAKE2b-256 d46aa985232d624b45cd133c8bbd6a31ff9f8f9597635a87d43edc89dc5d16bc

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