当前位置: 首页>>代码示例>>Python>>正文


Python flask_migrate.Migrate方法代码示例

本文整理汇总了Python中flask_migrate.Migrate方法的典型用法代码示例。如果您正苦于以下问题:Python flask_migrate.Migrate方法的具体用法?Python flask_migrate.Migrate怎么用?Python flask_migrate.Migrate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_migrate的用法示例。


在下文中一共展示了flask_migrate.Migrate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def __call__(self, app=None, directory='migrations', **kwargs):
        if app is None:
            app = self.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
            else:
                raise Exception(u"No database defined for app.")

        Migrate(app, db, self.directory)
        return app 
开发者ID:paxswill,项目名称:evesrp,代码行数:22,代码来源:manage.py

示例2: configure_db

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
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.
    """
    db.init_app(app)
    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:
                log.info('Initializing new DB from scratch')
                flask_migrate.upgrade(directory=migrations)

            # 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:
                log.info('Unstable DB schema, stamping original revision')
                flask_migrate.stamp(directory=migrations,
                                    revision='da9459a1f71c')

            if head != current:
                log.info('DB schema out of date, upgrading')
                flask_migrate.upgrade(directory=migrations) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:42,代码来源:webapp.py

示例3: deploy

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def deploy():
    """Run deployment tasks"""
    # Migrate database to latest revision
    upgrade() 
开发者ID:alisezer,项目名称:flask-template,代码行数:6,代码来源:stories.py

示例4: deploy

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def deploy():
    from flask_migrate import upgrade
    # Migrate db to latest revision.
    upgrade() 
开发者ID:mckinziebrandon,项目名称:DeepChatModels,代码行数:6,代码来源:manage.py

示例5: main

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def main():
    """Run migration command."""
    args = parse_arguments(sys.argv[1:])
    setup_config(args)
    configure_logging(args['log_level'])
    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']
        func(args) 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:13,代码来源:schema.py

示例6: migrate

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def migrate(app, db):
    test_migrations = os.path.join(os.path.dirname(__file__), "migrations")
    return Migrate(app, db, directory=test_migrations) 
开发者ID:mozilla-services,项目名称:python-dockerflow,代码行数:5,代码来源:test_flask.py

示例7: init

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
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
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

    db.init_app(app)
    # See http://piotr.banaszkiewicz.org/blog/2012/06/29/flask-sqlalchemy-init_app/, option 2
    db.app = app

    migrate = flask_migrate.Migrate(app, db) 
开发者ID:puffinrocks,项目名称:puffin,代码行数:15,代码来源:db.py

示例8: init_app

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def init_app(app):
    db.init_app(app)
    _migrate = Migrate(app, db)  # lgtm [py/unused-local-variable] 
开发者ID:ngoduykhanh,项目名称:PowerDNS-Admin,代码行数:5,代码来源:__init__.py

示例9: create_app

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def create_app(config_name):
    app = Flask(__name__, instance_relative_config=True)
    try:
      assert config_name == "development" or config_name == "production"
      app.config.from_object(app_config[config_name])
    except AssertionError:
      print ("[!] Helix production config not set... running in development state.")
      app.config.from_object(app_config['development'])
    from os import environ
    app.config.from_pyfile('config.py')
    Bootstrap(app)

    db.init_app(app)
    db.app = app
    login_manager.init_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
    app.register_blueprint(auth_blueprint)

    from .home import home as home_blueprint
    app.register_blueprint(home_blueprint)

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

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

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

    return app, db 
开发者ID:helix-iot,项目名称:helix-sandbox,代码行数:45,代码来源:__init__.py

示例10: create_app

# 需要导入模块: import flask_migrate [as 别名]
# 或者: from flask_migrate import Migrate [as 别名]
def create_app(extra_config_settings={}):
    """Create a Flask application.
    """
    # Instantiate Flask
    app = Flask(__name__)

    # Load common settings
    app.config.from_object('app.settings')
    # Load environment specific settings
    app.config.from_object('app.local_settings')
    # Load extra settings from extra_config_settings param
    app.config.update(extra_config_settings)

    # Setup Flask-SQLAlchemy
    db.init_app(app)

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

    # Setup Flask-Mail
    mail.init_app(app)

    # Setup WTForms CSRFProtect
    csrf_protect.init_app(app)

    # Register blueprints
    from .views import register_blueprints
    register_blueprints(app)

    # 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
    init_email_error_handler(app)

    # 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)

    @app.context_processor
    def context_processor():
        return dict(user_manager=user_manager)

    return app 
开发者ID:lingthio,项目名称:Flask-User-starter-app,代码行数:54,代码来源:__init__.py


注:本文中的flask_migrate.Migrate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。