Example #1
0
def setup_database(app):
    """Prepare the database. Create tables, run migrations etc."""

    def _pre_alembic_db():
        """ Checks if we are migrating from a pre-alembic ihatemoney
        """
        con = db.engine.connect()
        tables_exist = db.engine.dialect.has_table(con, 'project')
        alembic_setup = db.engine.dialect.has_table(con, 'alembic_version')
        return tables_exist and not alembic_setup

    sqlalchemy_url = app.config.get('SQLALCHEMY_DATABASE_URI')
    if sqlalchemy_url.startswith('sqlite:////tmp'):
        warnings.warn(
            'The database is currently stored in /tmp and might be lost at '
            'next reboot.'
        )

    db.init_app(app)
    db.app = app

    Migrate(app, db)
    migrations_path = os.path.join(app.root_path, 'migrations')

    if _pre_alembic_db():
        with app.app_context():
            # fake the first migration
            stamp(migrations_path, revision='b9a10d5d63ce')

    # auto-execute migrations on runtime
    with app.app_context():
        upgrade(migrations_path)
Example #2
0
def setup_database(app):
    """Prepare the database. Create tables, run migrations etc."""
    def _pre_alembic_db():
        """ Checks if we are migrating from a pre-alembic ihatemoney
        """
        con = db.engine.connect()
        tables_exist = db.engine.dialect.has_table(con, "project")
        alembic_setup = db.engine.dialect.has_table(con, "alembic_version")
        return tables_exist and not alembic_setup

    sqlalchemy_url = app.config.get("SQLALCHEMY_DATABASE_URI")
    if sqlalchemy_url.startswith("sqlite:////tmp"):
        warnings.warn(
            "The database is currently stored in /tmp and might be lost at "
            "next reboot.")

    db.init_app(app)
    db.app = app

    Migrate(app, db)
    migrations_path = os.path.join(app.root_path, "migrations")

    if _pre_alembic_db():
        with app.app_context():
            # fake the first migration
            stamp(migrations_path, revision="b9a10d5d63ce")

    # auto-execute migrations on runtime
    with app.app_context():
        upgrade(migrations_path)
Example #3
0
def setup_database(app):
    """Prepare the database. Create tables, run migrations etc."""

    def _pre_alembic_db():
        """ Checks if we are migrating from a pre-alembic ihatemoney
        """
        con = db.engine.connect()
        tables_exist = db.engine.dialect.has_table(con, 'project')
        alembic_setup = db.engine.dialect.has_table(con, 'alembic_version')
        return tables_exist and not alembic_setup

    db.init_app(app)
    db.app = app

    Migrate(app, db)
    migrations_path = os.path.join(app.root_path, 'migrations')

    if _pre_alembic_db():
        with app.app_context():
            # fake the first migration
            stamp(migrations_path, revision='b9a10d5d63ce')

    # auto-execute migrations on runtime
    with app.app_context():
        upgrade(migrations_path)