Пример #1
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connection = get_engine().connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
    )

    try:
        try:
            connection.execute("SHOW bdr.permit_ddl_locking")
            bdr = True
        except Exception:
            bdr = False

        with context.begin_transaction():
            if bdr:
                connection.execute("SET LOCAL bdr.permit_ddl_locking = true")
            context.run_migrations()
            grant_db_access(None, connection)
    finally:
        connection.close()
Пример #2
0
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    connection = get_engine().connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
    )

    try:
        try:
            connection.execute("SHOW bdr.permit_ddl_locking")
            bdr = True
        except Exception:
            bdr = False

        with context.begin_transaction():
            if bdr:
                connection.execute("SET LOCAL bdr.permit_ddl_locking = true")
            context.run_migrations()
            grant_db_access(None, connection)
    finally:
        connection.close()
Пример #3
0
 def execute(self, args):
     engine = get_engine()
     cmd = ['psql', '-d', engine.url.database] + args
     if engine.url.username:
         cmd += ['-U', engine.url.username]
     if engine.url.host:
         cmd += ['-h', engine.url.host]
     env = os.environ.copy()
     if engine.url.password:
         env['PGPASSWORD'] = engine.url.password
     os.execve('/usr/bin/psql', cmd, env)
Пример #4
0
 def execute(self, args):
     engine = get_engine()
     cmd = ['psql', '-d', engine.url.database] + args
     if engine.url.username:
         cmd += ['-U', engine.url.username]
     if engine.url.host:
         cmd += ['-h', engine.url.host]
     env = os.environ.copy()
     if engine.url.password:
         env['PGPASSWORD'] = engine.url.password
     os.execve('/usr/bin/psql', cmd, env)
Пример #5
0
 def setUp(self):
     super(DBTest, self).setUp()
     if not DBTest.postgres_initialized:
         self.skipTest("requires PostgreSQL")
     conn = get_engine().connect()
     for table in Base.metadata.non_materialized_view_tables:
         conn.execute(table.delete())
         if hasattr(table.c, 'id'):
             conn.execute("ALTER SEQUENCE {}_id_seq RESTART".format(table.name))
     for materialized_view in Base.metadata.materialized_views:
         materialized_view.refresh(conn)
     conn.close()
     self.session = self.create_session()
     self.db = self.session.db
     self.db.add(self.collection)
     self.db.commit()
Пример #6
0
 def setUp(self):
     super(DBTest, self).setUp()
     if not DBTest.postgres_initialized:
         self.skipTest("requires PostgreSQL")
     conn = get_engine().connect()
     for table in Base.metadata.non_materialized_view_tables:
         conn.execute(table.delete())
         if hasattr(table.c, 'id'):
             conn.execute("ALTER SEQUENCE {}_id_seq RESTART".format(
                 table.name))
     for materialized_view in Base.metadata.materialized_views:
         materialized_view.refresh(conn)
     conn.close()
     self.session = self.create_session()
     self.db = self.session.db
     self.db.add(self.collection)
     self.db.commit()
Пример #7
0
            page = int(request.args.get('page', 1))
        except ValueError:
            abort(400)
        if page < 1:
            abort(404)
        items = self.limit(items_per_page)\
                    .offset((page - 1) * items_per_page).all()
        if not items and page != 1:
            abort(404)
        if page == 1 and len(items) < items_per_page:
            total = len(items)
        else:
            total = self.order_by(None).count()
        return Pagination(self, page, items_per_page, total, items)

db = scoped_session(sessionmaker(autocommit=False, bind=get_engine(),
                                 query_cls=FrontendQuery))


class KoscheiFrontendSession(KoscheiSession):
    db = db
    log = logging.getLogger('koschei.frontend')

    def log_user_action(self, message, **kwargs):
        self.db.add(
            LogEntry(environment='frontend', user=g.user, message=message, **kwargs),
        )


session = KoscheiFrontendSession()
Пример #8
0
        if page < 1:
            abort(404)
        items = self.limit(items_per_page)\
                    .offset((page - 1) * items_per_page).all()
        if not items and page != 1:
            abort(404)
        if page == 1 and len(items) < items_per_page:
            total = len(items)
        else:
            total = self.order_by(None).count()
        return Pagination(self, page, items_per_page, total, items)


# Thread-local database session
db = scoped_session(
    sessionmaker(autocommit=False, bind=get_engine(), query_cls=FrontendQuery))


class KoscheiFrontendSession(KoscheiSession):
    """
    KoscheiSession with frontend-specific additions.
    """
    db = db
    log = logging.getLogger('koschei.frontend')

    def log_user_action(self, message, **kwargs):
        self.db.add(
            LogEntry(environment='frontend',
                     user=g.user,
                     message=message,
                     **kwargs), )
Пример #9
0
            abort(400)
        if page < 1:
            abort(404)
        items = self.limit(items_per_page)\
                    .offset((page - 1) * items_per_page).all()
        if not items and page != 1:
            abort(404)
        if page == 1 and len(items) < items_per_page:
            total = len(items)
        else:
            total = self.order_by(None).count()
        return Pagination(self, page, items_per_page, total, items)


# Thread-local database session
db = scoped_session(sessionmaker(autocommit=False, bind=get_engine(),
                                 query_cls=FrontendQuery))


class KoscheiFrontendSession(KoscheiSession):
    """
    KoscheiSession with frontend-specific additions.
    """
    db = db
    log = logging.getLogger('koschei.frontend')

    def log_user_action(self, message, **kwargs):
        self.db.add(
            LogEntry(environment='frontend', user=g.user, message=message, **kwargs),
        )