Simple migration command for Flask and Psycopg 3.
Project description
PostgreSQL Database Migrations for Flask with Psycopg
Synopsis
flask-migratepg
is a simple migrations tool for Flask and Psycopg 3.
- Install and setup the Flask extension.
- Place SQL migrations under the subdirectory
database/migrations/
. - Execute migrations with the command
flask migrate execute
.
Installation
$ pip install flask-migratepg
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)
Usage
Create a new migration SQL file:
$ flask migrate --help
$ flask migrate new --help
$ flask migrate new migration_name
Then to run migrations:
$ flask migrate execute --help
$ flask migrate execute
This will run migrations in alphabetical order and track them in a migrations table.
If there is a failure, the transaction will be rolled back.
Migration Files
Migrations are placed under database/migrations/
as an SQL file
(that is, with an .sql
filename extension.)
The recommended filename format is YYMMDD_NNN_migration_name.sql
, for example, 20240219_001_add_table_accounts.sql
.
Statements are separated as per standard SQL conventions with a semicolon.
These are just plain-text standard SQL files. Comments (lines beginning with --
) will be ignored.
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
Built Distribution
File details
Details for the file flask-migratepg-1.0.2.tar.gz
.
File metadata
- Download URL: flask-migratepg-1.0.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6642fc2c693f2526d010d152d5db093151b8babedb3addf66c9a8050d16e806b |
|
MD5 | ec8e0e84bf0985313a31109b29e550c6 |
|
BLAKE2b-256 | a6920c087fbd882d2da703bc133faca0ab27b28a2396d2edbfa6e7571b61d066 |
File details
Details for the file flask_migratepg-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: flask_migratepg-1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | faa3e9fa059569bd78cd314c36cc1536159a03e3074a6908d88c0f4ff082d8d6 |
|
MD5 | 172584261b5418cac11c05b042366b18 |
|
BLAKE2b-256 | 07ca7049deeff1dd05f0a044f53677b8ae28a340a1939dc5a46547ae8ad2edbf |