Simple migration command for Flask and Psycopg 3.
Project description
flask-migratepg
: Database Migrations for Flask and PostgreSQL with Psycopg
This is a simple migrations tool for Flask and Psycopg 3.
- Install and setup the Flask extension.
- Place SQL migrations under
database/migrations/
. - Execute migrations.
Setup in application:
from flask import Flask
from flask_migratepg import MigratePg
import os
app = Flask(__name__)
app.config.from_mapping(
MIGRATIONS_PATH=os.path.abspath('database/migrations'),
PSYCOPG_CONNINFO="dbname=example host=localhost user=example password=secret"
)
MigratePg(app)
Then to run migrations:
flask migrate execute
This will run migrations in alphabetical order and track them in a migrations table.
Migrations are placed under database/migrations/
as either an SQL or Python file
(that is, with an .sql
or .py
filename extension resepectively.)
An SQL migration will simply be executed.
A Python migration can implement a method migrate(conn)
. If this method is
present, it will be called. An example of this:
def migrate(conn):
cur = conn.cursor()
# ...
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
flask-migratepg-0.0.6.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for flask_migratepg-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15262448975628bae85909e2f29fb86626d3860af2cf7c372430690dcf2e6ccc |
|
MD5 | 5251bd42c207c51bbc9298b08a5af72e |
|
BLAKE2b-256 | c3a12c270a8ff99b64e3710eca4476048186ad01082b3de6958112f13b826840 |