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: manage.py From evesrp with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #2
Source File: webapp.py From ara-archive with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: stories.py From flask-template with MIT License | 5 votes |
def deploy(): """Run deployment tasks""" # Migrate database to latest revision upgrade()
Example #4
Source File: manage.py From DeepChatModels with MIT License | 5 votes |
def deploy(): from flask_migrate import upgrade # Migrate db to latest revision. upgrade()
Example #5
Source File: schema.py From cloudify-manager with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: test_flask.py From python-dockerflow with Mozilla Public License 2.0 | 5 votes |
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: db.py From puffin with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #8
Source File: __init__.py From PowerDNS-Admin with MIT License | 5 votes |
def init_app(app): db.init_app(app) _migrate = Migrate(app, db) # lgtm [py/unused-local-variable]
Example #9
Source File: __init__.py From helix-sandbox with GNU Affero General Public License v3.0 | 4 votes |
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
Example #10
Source File: __init__.py From Flask-User-starter-app with BSD 2-Clause "Simplified" License | 4 votes |
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