Quickstart

Minimal Application

A minimal Broadway-Migrate application looks something like this:

import broadway

factory = broadway.factory()

factory.add_extensions(
  'broadway_sqlalchemy',
  'broadway_migrate',
)

app = factory(__name__)

from broadway_sqlalchemy import extension as db

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    email = db.Column(db.String(120), unique=True)

    def __init__(self, username, email):
        self.username = username
        self.email = email

    def __repr__(self):
        return '<User %r>' % self.username

Save this as app.py, and run the the server using the flask command line.

$ export SQLALCHEMY_DATABASE_URI=sqlite:////tmp/test.db
$ export FLASK_APP=app.py
$ flask db init
$ flask db migrate
$ flask db upgrade

Broadway will use the extension to load and configure Flask-Migrate, an instance will be made available as broadway_migrate.extension.

You must initialise Flask-SQLAlchemy before hand, either by Broadway-SQLAlchemy or otherwise.