import sqlalchemy
from django.conf import settings


def create_engine():
    return sqlalchemy.create_engine(settings.SQL_REPORTING_DATABASE_URL)

@@ -48,100 +48,1928 @@
 ngs%0A
-%0A%0Adef create_engine():%0A    return sqlalchemy.create_engine(settings.SQL_REPORTING_DATABASE_URL
+from corehq.apps.userreports.models import DataSourceConfiguration%0A%0A%0ADEFAULT_ENGINE_ID = 'default'%0A%0A%0Adef create_engine():%0A    return sqlalchemy.create_engine(settings.SQL_REPORTING_DATABASE_URL)%0A%0A%0Aclass ConnectionManager(object):%0A    %22%22%22%0A    Object for dealing with connections.%0A    %22%22%22%0A%0A    def __init__(self):%0A        self._engines = %7B%7D%0A%0A    def get_engine(self, engine_id=DEFAULT_ENGINE_ID):%0A        %22%22%22%0A        Get an engine by ID. This should be a unique field identifying the connection,%0A        e.g. %22report-db-1%22%0A        %22%22%22%0A        if engine_id not in self._engines:%0A            engine = create_engine()%0A            self._engines%5Bengine_id%5D = engine%0A%0A        return self._engines%5Bengine_id%5D%0A%0A    def dispose_engine(self, engine_id=DEFAULT_ENGINE_ID):%0A        %22%22%22%0A        If found, disposes an engine and removes it from this, otherwise does nothing.%0A        %22%22%22%0A        if engine_id in self._engines:%0A            engine = self._engines.pop(engine_id)%0A            engine.dispose()%0A%0A    def dispose_all(self):%0A        %22%22%22%0A        Dispose all engines associated with this. Useful for tests.%0A        %22%22%22%0A        for engine_id in self._engines:%0A            self.dispose_engine(engine_id)%0A%0A    def _get_connection_string(self, engine_id):%0A        # for now this just always returns the same connection string for any%0A        # engine_id, but in the future we could make this function more complicated%0A        return %7B%0A            DEFAULT_ENGINE_ID: settings.SQL_REPORTING_DATABASE_URL%0A        %7D.get(engine_id, settings.SQL_REPORTING_DATABASE_URL)%0A%0A%0Adef get_engine_id(object):%0A    %22%22%22%0A    Given an object, get the engine id for it.%0A    %22%22%22%0A    # for now this only deals with data sources.%0A    assert isinstance(object, DataSourceConfiguration)%0A    # we can swap this out to specify multiple engines when we want to support multiple databases/schemas%0A    return DEFAULT_ENGINE_ID%0A%0A%0Aconnection_manager = ConnectionManager(
 )%0A

add stub ConnectionManager class and utility functions