Python flask_migrate.Migrate() Examples

The following are 10 code examples of flask_migrate.Migrate(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_migrate , or try the search function .
Example #1
Source File:    From evesrp with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def __call__(self, app=None, directory='migrations', **kwargs):
        if app is None:
            app =
            if app is None:
                raise Exception(u"No app specified")

        db = kwargs.pop('db', None)

        if not isinstance(app, flask.Flask):
            app = app(**kwargs)

        # Last ditch effort to get a database handle
        if db is None:
            if 'sqlalchemy' in app.extensions:
                db = app.extensions['sqlalchemy'].db
                raise Exception(u"No database defined for app.")

        Migrate(app, db,
        return app 
Example #2
Source File:    From ara-archive with GNU General Public License v3.0 5 votes vote down vote up
def configure_db(app):
    0.10 is the first version of ARA that ships with a stable database schema.
    We can identify a database that originates from before this by checking if
    there is an alembic revision available.
    If there is no alembic revision available, assume we are running the first
    revision which contains the latest state of the database prior to this.
    log = logging.getLogger(app.logger_name)

    if app.config.get('ARA_AUTOCREATE_DATABASE'):
        with app.app_context():
            migrations = app.config['DB_MIGRATIONS']
            flask_migrate.Migrate(app, db, directory=migrations)
            config = app.extensions['migrate'].migrate.get_config(migrations)

            # Verify if the database tables have been created at all
            inspector = Inspector.from_engine(db.engine)
            if len(inspector.get_table_names()) == 0:
      'Initializing new DB from scratch')

            # Get current alembic head revision
            script = ScriptDirectory.from_config(config)
            head = script.get_current_head()

            # Get current revision, if available
            connection = db.engine.connect()
            context = MigrationContext.configure(connection)
            current = context.get_current_revision()

            if not current:
      'Unstable DB schema, stamping original revision')

            if head != current:
      'DB schema out of date, upgrading')
Example #3
Source File:    From flask-template with MIT License 5 votes vote down vote up
def deploy():
    """Run deployment tasks"""
    # Migrate database to latest revision
Example #4
Source File:    From DeepChatModels with MIT License 5 votes vote down vote up
def deploy():
    from flask_migrate import upgrade
    # Migrate db to latest revision.
Example #5
Source File:    From cloudify-manager with Apache License 2.0 5 votes vote down vote up
def main():
    """Run migration command."""
    args = parse_arguments(sys.argv[1:])
    config.instance.can_load_from_db = False
    app = server.CloudifyFlaskApp(load_config=False)
    with app.app_context():
        flask_migrate.Migrate(app=app, db=storage.db)
        func = args['func']
Example #6
Source File:    From python-dockerflow with Mozilla Public License 2.0 5 votes vote down vote up
def migrate(app, db):
    test_migrations = os.path.join(os.path.dirname(__file__), "migrations")
    return Migrate(app, db, directory=test_migrations) 
Example #7
Source File:    From puffin with GNU Affero General Public License v3.0 5 votes vote down vote up
def init():
    url = get_url(app.config["DB_USER"], app.config["DB_PASSWORD"],
        app.config["DB_HOST"], app.config["DB_PORT"], app.config["DB_NAME"])
    app.config['SQLALCHEMY_DATABASE_URI'] = url

    # Track modifications of objects and emit signals, expensive, perhaps disable

    # See, option 2 = app

    migrate = flask_migrate.Migrate(app, db) 
Example #8
Source File:    From PowerDNS-Admin with MIT License 5 votes vote down vote up
def init_app(app):
    _migrate = Migrate(app, db)  # lgtm [py/unused-local-variable] 
Example #9
Source File:    From helix-sandbox with GNU Affero General Public License v3.0 4 votes vote down vote up
def create_app(config_name):
    app = Flask(__name__, instance_relative_config=True)
      assert config_name == "development" or config_name == "production"
    except AssertionError:
      print ("[!] Helix production config not set... running in development state.")
    from os import environ

    db.init_app(app) = app
    login_manager.login_message = "You must be logged in to access this page."
    login_manager.login_view = "auth.login"
    migrate = Migrate(app, db)

    from app import models

    from .admin import admin as admin_blueprint
    app.register_blueprint(admin_blueprint, url_prefix='/admin')

    from .auth import auth as auth_blueprint

    from .home import home as home_blueprint

    def forbidden(error):
      return render_template('errors/403.html', title='Forbidden'), 403

    def page_not_found(error):
      return render_template('errors/404.html', title='Page Not Found'), 404

    def internal_server_error(error):
      return render_template('errors/500.html', title='Server Error'), 500

    return app, db 
Example #10
Source File:    From Flask-User-starter-app with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def create_app(extra_config_settings={}):
    """Create a Flask application.
    # Instantiate Flask
    app = Flask(__name__)

    # Load common settings
    # Load environment specific settings
    # Load extra settings from extra_config_settings param

    # Setup Flask-SQLAlchemy

    # Setup Flask-Migrate
    migrate.init_app(app, db)

    # Setup Flask-Mail

    # Setup WTForms CSRFProtect

    # Register blueprints
    from .views import register_blueprints

    # Define bootstrap_is_hidden_field for flask-bootstrap's bootstrap_wtf.html
    from wtforms.fields import HiddenField

    def is_hidden_field_filter(field):
        return isinstance(field, HiddenField)

    app.jinja_env.globals['bootstrap_is_hidden_field'] = is_hidden_field_filter

    # Setup an error-logger to send emails to app.config.ADMINS

    # Setup Flask-User to handle user account related forms
    from .models.user_models import User
    from .views.main_views import user_profile_page

    # Setup Flask-User
    user_manager = UserManager(app, db, User)

    def context_processor():
        return dict(user_manager=user_manager)

    return app