No project description provided
Project description
Many: A library to migrate anything!
Managing state changes in data stores is an important part of the development process. There are many great migration tool available for SQL-like databases. However, there is lack of support for other data stores. Because of that I created a small library called many
which can be used to build your own migration tool for any data store.
Creating your own application
To create your own migration application for your data store:
- Subclass the
MigrationEngine
class and implement its methods. - Optionally, create a customized migration template by using
Mako
templates. - Initialize your application using
init_app
function with your customizedMigrationEngine
andTemplate
- Run you application.
How this would look like:
# migration_app.py
from many import MigrationEngine, init_app
class CustomEngine(MigrationEngine):
def init_remote(self):
# Add logic to initialize a place where the state can be maintained (e.g. a table).
def remote_exists(self) -> bool:
# Add logic to check whether the remote state exists.
def update_remote(self, state: str):
# Add logic to update the remote state to the provided state
def get_remote(self) -> str:
# Add logic to get the remote state
def prepare_args(self) -> Tuple[Any]:
# Logic to pass any argument to the actual migration (e.g. a session/connection object).
if __name__ == "__main__":
app = init_app(CustomEngine())
app()
Now, this application can be used as follows:
python migration_app.py revision create -m "My first migration"
to create your first revision in theversions
folder.- Modify the generated file in the
versions
to customize your migration. python migration_app.py migrate up
to upgrade the state to the latest migration.python migration_app.py migrate down
to downgrade the state one level. Usepython migration_app.py migrate down --level base
to downgrade completely.
Examples
I have added some examples to showcase how to use the library by implementing some migration applications for:
- Elasticsearch:
examples/elasticsearch
- Apache Iceberg:
examples/iceberg
- PostgreSQL:
examples/postgresql
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
many_migrations-0.3.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for many_migrations-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54d6f5ef63f6f31327265f012acf2f33b74c72fd773234ad29bcd1d006d15391 |
|
MD5 | fac4bb3ba952f4e58103fb95cd781696 |
|
BLAKE2b-256 | e4df5852ca05d1e1b2a88b9e49efb87fb25d6d494e8b2044af7059acbf5c6ddf |