Last active
May 30, 2020 15:49
-
-
Save omarryhan/cb7bf6d7142c154496ba6623a56326c2 to your computer and use it in GitHub Desktop.
Sanic/Gino/Alembic migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do the first 6 steps only once. | |
1. pip install --user alembic | |
2. bash: ``cd {{my_project}} && alembic init alembic`` | |
3. bash: ``text_editor {{my_project}}/alembic.ini`` | |
4. Change: "sqlalchemy.url = postgres://{{username}}:{{password}}@{{address}}/{{db_name}}" | |
5. bash: ``text_editor {{my_project}}/alembic/env.py`` | |
6. Now, import your metadata/db object from your app.: | |
# {{my_project}}/{{my_project_dir}}/app.py | |
# an example app | |
from gino.ext.sanic import Gino | |
from sanic import sanic | |
# Make sure you also configure Gino from app.config | |
# https://github.com/fantix/gino/blob/master/docs/sanic.rst | |
app = Sanic() | |
db = Gino | |
db.init_app(app) | |
# {{my_project}}/alembic/env.py | |
from {{my_project_dir}} import db | |
target_metadata = db | |
# Now, whenever you want to do migrations, execute the following in a bash terminal | |
# Autogenerates migrations based on the models you defined in your app | |
7. alembic revision -m "Migration message" --autogenerate --head head | |
# Applies migrations | |
8. alembic upgrade head | |
Done! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i can't use