A Python helper library for applications using Reshape
Project description
Reshape Python helper
This is a Python helper library for the automated, zero-downtime schema migration tool Reshape. To achieve zero-downtime migrations, Reshape requires that your application runs a simple query when it opens a connection to the database to select the right schema. This library automates that process with a simple method which will return the correct query for your application. It also works great with Django!
Installation
pip install reshape_helper
Usage
The library includes a schema_query method which will find all your Reshape migration files and determine the right schema query to run. Here's an example of how to use it:
import schema_query from reshape_helper
# Run the schema query against your database when you open a new connection
db.execute(schema_query())
By default, schema_query will look for migrations files in migrations/, but you can specify your own directories as well:
import schema_query from reshape_helper
query = schema_query(
"src/users/migrations",
"src/todos/migrations",
)
Usage with Django
Using Reshape for zero-downtime migrations with Django is really simple. After installing reshape_helper, update your app.py and add a handler for the connection_created signal. This handler will run the schema query whenever a new database connection is opened:
from django.db.backends.signals import connection_created
import schema_query from reshape_helper
class YourAppConfig(AppConfig):
def ready(self):
connection_created.connect(new_connection_handler)
def new_connection_handler(sender, connection, **kwargs):
connection.cursor().execute(schema_query())
Now your Rails app is ready for use with Reshape. Rather than creating standard Django migrations, you should create Reshape migration files in migrations/. If you'd prefer to use other folders for your migrations, you can pass them to schema_query():
def new_connection_handler(sender, connection, **kwargs):
connection.cursor().execute(schema_query("yourapp/users/migrations", "yourapp/todo/migrations"))
License
Released under 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reshape_helper-0.1.0.tar.gz.
File metadata
- Download URL: reshape_helper-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd013f218aead3486f701b55d4cd3d21ad5e71b538e7c0ecdf2e189e80cc7af
|
|
| MD5 |
1d49704768d7459ee42c5d18cffd20c6
|
|
| BLAKE2b-256 |
ad2b6ae4d20f6a39e1717afb78a043dfd940c1971c3e206f4c286dfb7d61455b
|
File details
Details for the file reshape_helper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reshape_helper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
450074c661baaadf0f9d64b7af83fd2ffac29d2f42b4952cdbabcac3f15b704c
|
|
| MD5 |
c4a8ef8f1543659e6f152efaeebbda08
|
|
| BLAKE2b-256 |
047ca54586d81c582630496ec0aab28af9d56cd6db6a487637fa17961c66e657
|