Skip to main content

A tool to apply pure SQL migrations to PostgreSQLdatabases at runtime.

Project description

itinerary

A tool to apply pure SQL migrations to PostgreSQL databases at runtime.

Itinerary uses PostgreSQL’s advisory locks feature to prevent multiple instances from running migrations simultaneously. As such, it’s suitable for use in horizontally scalable applications.

Installation

pip install itinerary

Usage

Put raw SQL files in your migration directory, e.g.:

migrations/0001_create_table.sql
migrations/0002_add_column.sql
migrations/0003_create_index.sql

Then run the auto_migrate function before your application starts.

Flask example

import itinerary
from flask import Flask
app = Flask(__name__)

if __name__ == '__main__':
    conn = psycopg2.connect(host='localhost')
    itinerary.auto_migrate(conn)
    app.run()

uWSGI example

import itinerary
from uwsgidecorators import postfork

@postfork
def migrate_db():
    conn = psycopg2.connect(host='localhost')
    itinerary.auto_migrate(conn)

Configuration

itinerary.auto_migrate(connection, path='migrations',
                       version_table='_version', lock_id=0)
  • path – Directory to scan for migration files.
  • version_table – Table to use to keep track of applied migrations. If it doesn’t exist, itinerary will create it.
  • lock_id – The key to use when acquiring and releasing a PostgreSQL advisory lock.

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

itinerary-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

itinerary-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file itinerary-1.0.0.tar.gz.

File metadata

  • Download URL: itinerary-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for itinerary-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b740c1ec8de21cad51918152d4b1bfc0ca2918280f7ba3856b4d441e0a811d8e
MD5 0fd8a7f53cad24a32e0f84bc26d4ea41
BLAKE2b-256 ac4bf4ad9de89614257baa9367b94df21c65cf0ca243b6ab2e723aa64ab06e4f

See more details on using hashes here.

File details

Details for the file itinerary-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: itinerary-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for itinerary-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a7734e594e90125cbcde8939be86882f9c727304bbb435043d016848b56e887
MD5 b600a947c649090e11118bbd1a43a045
BLAKE2b-256 25624dfe1a165c43266949fc8c0cef34ea6390dda2146a79fde9e8ca8f020d8b

See more details on using hashes here.

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