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.5.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_migratepg-0.0.5-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file flask-migratepg-0.0.5.tar.gz.

File metadata

  • Download URL: flask-migratepg-0.0.5.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for flask-migratepg-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2cf442f16668296693987c1a06a8353dab83db1532dabf6dc3fb74a3b5f6d04a
MD5 1ccd838308f63ad911df7c951e211ca2
BLAKE2b-256 cb586cd16c0f58ca8e726bf456bc08b45fcb8eac2a44d76eb734235a01cb9521

See more details on using hashes here.

File details

Details for the file flask_migratepg-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_migratepg-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4fe98dc2333111f9b6ffc0ebaa9ca251ff8e24e09bd5872a683357aa89672195
MD5 d0584b0deff0452fbc6ca072d4a38585
BLAKE2b-256 791445ce0bb93b81898c121464d950398fe78b0d64f999cd0c8b2489f0bf0f48

See more details on using hashes here.

Supported by

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