fix and improve setup of storage factory and storage
This commit is contained in:
parent
73ac0af54e
commit
d5a8068261
3 changed files with 15 additions and 11 deletions
|
@ -2,9 +2,10 @@
|
|||
|
||||
"""Compatibility layer on scopes.storage: common functionality."""
|
||||
|
||||
from sqlalchemy import Table, Column, Index, BigInteger, Text
|
||||
from sqlalchemy import Table, Column, Index, Text
|
||||
|
||||
from scopes.storage import common
|
||||
from scopes.storage.db import postgres
|
||||
|
||||
|
||||
class Storage(common.Storage):
|
||||
|
@ -31,11 +32,16 @@ class Storage(common.Storage):
|
|||
return createUidTable(self)
|
||||
|
||||
|
||||
class StorageFactory(postgres.StorageFactory):
|
||||
|
||||
storageClass = Storage
|
||||
|
||||
|
||||
def createUidTable(storage):
|
||||
metadata = storage.metadata
|
||||
cols = [Column('legacy', BigInteger, primary_key=True),
|
||||
cols = [Column('legacy', storage.db.IdType, primary_key=True),
|
||||
Column('prefix', Text, nullable=False),
|
||||
Column('id', BigInteger, nullable=False)]
|
||||
Column('id', storage.db.IdType, nullable=False)]
|
||||
idxs = [Index('idx_uid_mapping_prefix_id', 'prefix', 'id', unique=True)]
|
||||
table = Table('uid_mapping', metadata, *(cols+idxs), extend_existing=True)
|
||||
metadata.create_all(storage.engine)
|
||||
|
|
|
@ -18,15 +18,15 @@ from loops.organize.tests import setupObjectsForTesting
|
|||
from loops.storage.compat.common import Storage
|
||||
from loops import util
|
||||
|
||||
from scopes.storage.db.postgres import StorageFactory
|
||||
from loops.storage.compat.common import StorageFactory
|
||||
|
||||
factory = StorageFactory(config, storageClass=Storage)
|
||||
storage = factory(schema='testing')
|
||||
util.storageFactory = StorageFactory(config)
|
||||
|
||||
|
||||
class Glob(object):
|
||||
pass
|
||||
|
||||
storage = util.storageFactory(schema='testing')
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
|
@ -41,7 +41,6 @@ class TestCase(unittest.TestCase):
|
|||
loopsId = util.getUidForObject(loopsRoot)
|
||||
setupData = setupObjectsForTesting(site, g.concepts)
|
||||
g.johnC = setupData.johnC
|
||||
g.storage = storage
|
||||
|
||||
@classmethod
|
||||
def cleanup(cls):
|
||||
|
|
5
util.py
5
util.py
|
@ -25,11 +25,10 @@ except ImportError:
|
|||
import cybertools
|
||||
from cybertools.meta.interfaces import IOptions
|
||||
from loops.browser.util import html_quote
|
||||
from loops.storage.compat.common import Storage
|
||||
|
||||
import config
|
||||
from scopes.storage.db.postgres import StorageFactory
|
||||
storageFactory = StorageFactory(config, storageClass=Storage)
|
||||
from loops.storage.compat.common import StorageFactory
|
||||
storageFactory = StorageFactory(config)
|
||||
|
||||
_ = MessageFactory('loops')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue