Coder Social home page Coder Social logo

itinerary's Introduction

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.

itinerary's People

Contributors

awkspace avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

homerjsimpson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.