Пример #1
0
def prepare():
    """Initializes an empty database (creates tables, sets alembic rev to HEAD)"""
    tables = get_all_tables(db)
    if 'alembic_version' not in tables['public']:
        print colored('Setting the alembic version to HEAD', 'green')
        stamp()
        PluginScriptDirectory.dir = os.path.join(current_app.root_path, 'core', 'plugins', 'alembic')
        alembic.command.ScriptDirectory = PluginScriptDirectory
        plugin_msg = cformat("%{cyan}Setting the alembic version of the %{cyan!}{}%{reset}%{cyan} "
                             "plugin to HEAD%{reset}")
        for plugin in plugin_engine.get_active_plugins().itervalues():
            if not os.path.exists(plugin.alembic_versions_path):
                continue
            print plugin_msg.format(plugin.name)
            with plugin.plugin_context():
                stamp()
        # Retrieve the table list again, just in case we created unexpected hables
        tables = get_all_tables(db)

    tables['public'] = [t for t in tables['public'] if not t.startswith('alembic_version')]
    if any(tables.viewvalues()):
        print colored('Your database is not empty!', 'red')
        print colored('If you just added a new table/model, create an alembic revision instead!', 'yellow')
        print
        print 'Tables in your database:'
        for schema, schema_tables in sorted(tables.items()):
            for t in schema_tables:
                print cformat('  * %{cyan}{}%{reset}.%{cyan!}{}%{reset}').format(schema, t)
        return
    if not _require_extensions('unaccent', 'pg_trgm'):
        return
    print colored('Creating tables', 'green')
    db.create_all()
Пример #2
0
def create_schema(uri, pkg_name):
    app = Flask('schema generator')
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    list(load_all_modules(pkg_name))
    db.init_app(app)
    with app.app_context():
        db.create_all()
Пример #3
0
def create_schema(uri, pkg_name):
    app = Flask('schema generator')
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    list(load_all_modules(pkg_name))
    db.init_app(app)
    with app.app_context():
        db.create_all()
Пример #4
0
def prepare():
    """Initializes an empty database (creates tables, sets alembic rev to HEAD)"""
    tables = get_all_tables(db)
    if 'alembic_version' not in tables['public']:
        print colored('Setting the alembic version to HEAD', 'green')
        stamp()
        PluginScriptDirectory.dir = os.path.join(current_app.root_path, 'core', 'plugins', 'alembic')
        alembic.command.ScriptDirectory = PluginScriptDirectory
        plugin_msg = cformat("%{cyan}Setting the alembic version of the %{cyan!}{}%{reset}%{cyan} "
                             "plugin to HEAD%{reset}")
        for plugin in plugin_engine.get_active_plugins().itervalues():
            if not os.path.exists(plugin.alembic_versions_path):
                continue
            print plugin_msg.format(plugin.name)
            with plugin.plugin_context():
                stamp()
        # Retrieve the table list again, just in case we created unexpected hables
        tables = get_all_tables(db)

    tables['public'] = [t for t in tables['public'] if not t.startswith('alembic_version')]
    if any(tables.viewvalues()):
        print colored('Your database is not empty!', 'red')
        print colored('If you just added a new table/model, create an alembic revision instead!', 'yellow')
        print
        print 'Tables in your database:'
        for schema, schema_tables in sorted(tables.items()):
            for t in schema_tables:
                print cformat('  * %{cyan}{}%{reset}.%{cyan!}{}%{reset}').format(schema, t)
        return
    if not _require_extensions('unaccent', 'pg_trgm'):
        return
    print colored('Creating tables', 'green')
    db.create_all()
Пример #5
0
def database(app, postgresql):
    """Creates a test database which is destroyed afterwards

    Used only internally, if you need to access the database use `db` instead to ensure
    your modifications are not persistent!
    """
    app.config['SQLALCHEMY_DATABASE_URI'] = postgresql
    configure_db(app)
    update_session_options(db_)
    if 'INDICO_TEST_DATABASE_URI' in os.environ and os.environ.get('INDICO_TEST_DATABASE_HAS_TABLES') == '1':
        yield db_
        return
    with app.app_context():
        db_.create_all()
    yield db_
    db_.session.remove()
    with app.app_context():
        delete_all_tables(db_)
Пример #6
0
def database(app, postgresql):
    """Creates a test database which is destroyed afterwards

    Used only internally, if you need to access the database use `db` instead to ensure
    your modifications are not persistent!
    """
    app.config['SQLALCHEMY_DATABASE_URI'] = postgresql
    configure_db(app)
    update_session_options(db_)
    if 'INDICO_TEST_DATABASE_URI' in os.environ and os.environ.get('INDICO_TEST_DATABASE_HAS_TABLES') == '1':
        yield db_
        return
    with app.app_context():
        db_.create_all()
    yield db_
    db_.session.remove()
    with app.app_context():
        delete_all_tables(db_)
Пример #7
0
def prepare():
    """Initializes an empty database (creates tables, sets alembic rev to HEAD)"""
    tables = get_all_tables(db)
    if 'alembic_version' not in tables['public']:
        print colored('Setting the alembic version to HEAD', 'green')
        stamp()
        # Retrieve the table list again, that way we fail if the alembic version table was not created
        tables = get_all_tables(db)
    tables['public'].remove('alembic_version')
    if any(tables.viewvalues()):
        print colored('Your database is not empty!', 'red')
        print colored('If you just added a new table/model, create an alembic revision instead!', 'yellow')
        print
        print 'Tables in your database:'
        for schema, schema_tables in sorted(tables.items()):
            for t in schema_tables:
                print cformat('  * %{cyan}{}%{reset}.%{cyan!}{}%{reset}').format(schema, t)
        return
    print colored('Creating tables', 'green')
    db.create_all()
Пример #8
0
def prepare():
    """Initializes an empty database (creates tables, sets alembic rev to HEAD)"""
    tables = get_all_tables(db)
    if 'alembic_version' not in tables['public']:
        print colored('Setting the alembic version to HEAD', 'green')
        stamp()
        # Retrieve the table list again, that way we fail if the alembic version table was not created
        tables = get_all_tables(db)
    tables['public'].remove('alembic_version')
    if any(tables.viewvalues()):
        print colored('Your database is not empty!', 'red')
        print colored(
            'If you just added a new table/model, create an alembic revision instead!',
            'yellow')
        print
        print 'Tables in your database:'
        for schema, schema_tables in sorted(tables.items()):
            for t in schema_tables:
                print cformat(
                    '  * %{cyan}{}%{reset}.%{cyan!}{}%{reset}').format(
                        schema, t)
        return
    print colored('Creating tables', 'green')
    db.create_all()
Пример #9
0
 def setUp(self):
     db.create_all()
     self.init_db()