mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
Models: Refactor common code out between Galaxy and Tool Shed related to create_engine.
This commit is contained in:
@@ -8,7 +8,7 @@ import logging
|
||||
import pkg_resources
|
||||
import inspect
|
||||
|
||||
from sqlalchemy import and_, asc, Boolean, Column, create_engine, DateTime, desc, ForeignKey, Integer, MetaData, not_, Numeric, select, String, Table, TEXT, Unicode, UniqueConstraint
|
||||
from sqlalchemy import and_, asc, Boolean, Column, DateTime, desc, ForeignKey, Integer, MetaData, not_, Numeric, select, String, Table, TEXT, Unicode, UniqueConstraint
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.orderinglist import ordering_list
|
||||
from sqlalchemy.types import BigInteger
|
||||
@@ -16,12 +16,11 @@ from sqlalchemy.orm import backref, object_session, relation, scoped_session, se
|
||||
from sqlalchemy.orm.collections import attribute_mapped_collection
|
||||
|
||||
from galaxy import model
|
||||
from galaxy.model.orm import load_egg_for_url
|
||||
from galaxy.model.orm.engine_factory import build_engine
|
||||
from galaxy.model.custom_types import JSONType, MetadataType, TrimmedString, UUIDType
|
||||
from galaxy.security import GalaxyRBACAgent
|
||||
from galaxy.util.bunch import Bunch
|
||||
|
||||
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
metadata = MetaData()
|
||||
@@ -2008,19 +2007,8 @@ def init( file_path, url, engine_options={}, create_tables=False, database_query
|
||||
# Use PBKDF2 password hashing?
|
||||
model.User.use_pbkdf2 = use_pbkdf2
|
||||
# Load the appropriate db module
|
||||
load_egg_for_url( url )
|
||||
# Should we use the logging proxy?
|
||||
if database_query_profiling_proxy:
|
||||
import galaxy.model.orm.logging_connection_proxy as logging_connection_proxy
|
||||
proxy = logging_connection_proxy.LoggingProxy()
|
||||
# If metlog is enabled, do micrologging
|
||||
elif trace_logger:
|
||||
import galaxy.model.orm.logging_connection_proxy as logging_connection_proxy
|
||||
proxy = logging_connection_proxy.TraceLoggerProxy( trace_logger )
|
||||
else:
|
||||
proxy = None
|
||||
# Create the database engine
|
||||
engine = create_engine( url, proxy=proxy, **engine_options )
|
||||
engine = build_engine( url, engine_options, database_query_profiling_proxy, trace_logger )
|
||||
|
||||
# Connect the metadata to the database.
|
||||
metadata.bind = engine
|
||||
# Clear any existing contextual sessions and reconfigure
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from galaxy.model.orm import load_egg_for_url
|
||||
|
||||
|
||||
def build_engine(url, engine_options, database_query_profiling_proxy=False, trace_logger=None):
|
||||
load_egg_for_url( url )
|
||||
|
||||
# Should we use the logging proxy?
|
||||
if database_query_profiling_proxy:
|
||||
import galaxy.model.orm.logging_connection_proxy as logging_connection_proxy
|
||||
proxy = logging_connection_proxy.LoggingProxy()
|
||||
# If metlog is enabled, do micrologging
|
||||
elif trace_logger:
|
||||
import galaxy.model.orm.logging_connection_proxy as logging_connection_proxy
|
||||
proxy = logging_connection_proxy.TraceLoggerProxy( trace_logger )
|
||||
else:
|
||||
proxy = None
|
||||
|
||||
# Create the database engine
|
||||
engine = create_engine( url, proxy=proxy, **engine_options )
|
||||
return engine
|
||||
@@ -11,7 +11,7 @@ from galaxy.webapps.tool_shed.model import *
|
||||
from galaxy.model.orm import *
|
||||
from galaxy.model.custom_types import *
|
||||
from galaxy.util.bunch import Bunch
|
||||
from galaxy.model.orm import load_egg_for_url
|
||||
from galaxy.model.orm.engine_factory import build_engine
|
||||
import galaxy.webapps.tool_shed.util.shed_statistics as shed_statistics
|
||||
import galaxy.webapps.tool_shed.util.hgweb_config
|
||||
from galaxy.webapps.tool_shed.security import CommunityRBACAgent
|
||||
@@ -309,10 +309,8 @@ mapper( RepositoryCategoryAssociation, RepositoryCategoryAssociation.table,
|
||||
|
||||
def init( file_path, url, engine_options={}, create_tables=False ):
|
||||
"""Connect mappings to the database"""
|
||||
# Load the appropriate db module
|
||||
load_egg_for_url( url )
|
||||
# Create the database engine
|
||||
engine = create_engine( url, **engine_options )
|
||||
engine = build_engine( url, engine_options )
|
||||
# Connect the metadata to the database.
|
||||
metadata.bind = engine
|
||||
# Clear any existing contextual sessions and reconfigure
|
||||
|
||||
Reference in New Issue
Block a user