# Path: tkp/db/model.py
# SCHEMA_VERSION = 40


import logging
import numpy
import tkp.config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
from tkp.utility import substitute_inf
from tkp.db.model import SCHEMA_VERSION
        from psycopg2.extensions import (ISOLATION_LEVEL_AUTOCOMMIT,
                                            ISOLATION_LEVEL_READ_COMMITTED)
                                            (self.engine,
                                             self.user,
                                             self.password,
                                             self.host,
                                             self.port,
                                             self.database),
                                            echo=False,
                                            poolclass=NullPool,
                                            )
        self.Session = sessionmaker(bind=self.alchemy_engine)
        self.session = self.Session()

    def connect(self, check=True):
        """
        connect to the configured database

        args:
            check (bool): check if schema version is correct
        """
        logger.info("connecting to database...")

        self._connection = self.alchemy_engine.connect()
        self._connection.execution_options(autocommit=False)

        if check:
            # Check that our database revision matches that expected by the
            # codebase.
            q = "SELECT value FROM version WHERE name='revision'"
            cursor = self.connection.execute(q)
            schema_version = cursor.fetchone()[0]

# Path: tkp/db/model.py
# SCHEMA_VERSION = 40


# Path: tkp/db/database.py
import logging
import numpy
import tkp.config
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import NullPool
from tkp.utility import substitute_inf
from tkp.db.model import SCHEMA_VERSION
        from psycopg2.extensions import (ISOLATION_LEVEL_AUTOCOMMIT,
                                            ISOLATION_LEVEL_READ_COMMITTED)

                                            (self.engine,
                                             self.user,
                                             self.password,
                                             self.host,
                                             self.port,
                                             self.database),
                                            echo=False,
                                            poolclass=NullPool,
                                            )
        self.Session = sessionmaker(bind=self.alchemy_engine)
        self.session = self.Session()

    def connect(self, check=True):
        """
        connect to the configured database

        args:
            check (bool): check if schema version is correct
        """
        logger.info("connecting to database...")

        self._connection = self.alchemy_engine.connect()
        self._connection.execution_options(autocommit=False)

        if check:
            # Check that our database revision matches that expected by the
            # codebase.
            q = "SELECT value FROM version WHERE name='revision'"
            cursor = self.connection.execute(q)
            schema_version = cursor.fetchone()[0]

            if schema_version != SCHEMA_VERSION: