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()
# ...
cur.execute('commit')
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.4.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for flask_migratepg-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a68af04f6e778760492ad9493fe0e82b3ea4f167d3af9f4c9d4c76e39f23dfaa |
|
MD5 | 468870ea6e41ce0332f501e9ebb999f8 |
|
BLAKE2b-256 | d361fd6b840d2f832da0338ccf0b06afac57d8717d518358616af580f4fbd500 |