Skip to main content

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.

  1. Install and setup the Flask extension.
  2. Place SQL migrations under database/migrations/.
  3. 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


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)

Uploaded Source

Built Distribution

flask_migratepg-0.0.6-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page