This release is a pre-release and may not be stable for production use.
alembic-migrate
alembic-migrate is a framework-independent fork of flask-migrate.
Installation
To install, run pip install alembic-migrate
Usage
Create the following file structure:
model/
├── __init__.py
├── base.py
├── book.py
Then declare your SQLAlchemy Base and connection string in model/base.py.
Note: the connection string doesn't need to match your
app's DB connection, it's only used for migrations.
# model/base.py
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
def get_base():
return {'base': Base, 'sqlalchemy_url': 'sqlite:///demo.db'}
Let's add a model in model/book.py:
from .base import Base
from sqlalchemy import Integer, String, Column
class Book(Base):
__tablename__ = 'books'
name = Column(String, primary_key=True)
year = Column(Integer)
Now cd .. so that you are out of the model package and run:
alembic-db initto setup the templatealembic-db migrateto create a migration
You can also check out the example folder in this repo.
Configuring base module
The base module contains get_base() -> dict. By default model.base is used but you can change the environment variable:
export ALEMBIC_BASE="my_model.base"
Customize model import logic
By default, all *.py files in the same package as the base will be loaded.
However if you want to split your models in subpackages or have custom logic
you should implement import_models inside your base module.
def import_models():
from . import car, book
from .sub import other_models
def get_base():
return ...
Metadata
Release files for alembic-migrate 2.5.9.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| alembic-migrate-2.5.9.dev0.tar.gz | 12.1 kB | Details |
Release files / alembic-migrate-2.5.9.dev0.tar.gz
| Download URL | alembic-migrate-2.5.9.dev0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b68eac007c8ea855b8e78312936ac9433600881b14d0c8428a059e5fab45aa5
|
|
BLAKE2b-256 checksum How to use checksums |
7dc1a1994c61ecc693816a4eceeab722a491ddcf8f96db9616ac6e2cd7de2d20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.23.4 CPython/3.6.4
|