mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
new orm class method table_ensure
This commit is contained in:
parent
c14bae6050
commit
246dfb5b7e
@ -175,6 +175,22 @@ class Document(dict, object):
|
|||||||
'''
|
'''
|
||||||
rr.table_create(cls.table).run()
|
rr.table_create(cls.table).run()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def table_ensure(cls, rr):
|
||||||
|
'''
|
||||||
|
Creates the table if it doesn't exist.
|
||||||
|
'''
|
||||||
|
dbs = rr.db_list().run()
|
||||||
|
if not rr.dbname in dbs:
|
||||||
|
logging.info('creating rethinkdb database %s', repr(rr.dbname))
|
||||||
|
rr.db_create(rr.dbname).run()
|
||||||
|
tables = rr.table_list().run()
|
||||||
|
if not cls.table in tables:
|
||||||
|
logging.info(
|
||||||
|
'creating rethinkdb table %s in database %s',
|
||||||
|
repr(cls.table), repr(rr.dbname))
|
||||||
|
cls.table_create(rr)
|
||||||
|
|
||||||
def __init__(self, rr, d={}):
|
def __init__(self, rr, d={}):
|
||||||
dict.__setattr__(self, 'rr', rr)
|
dict.__setattr__(self, 'rr', rr)
|
||||||
self._pk = None
|
self._pk = None
|
||||||
|
@ -284,6 +284,7 @@ def test_orm(rr):
|
|||||||
table = 'some_doc'
|
table = 'some_doc'
|
||||||
|
|
||||||
SomeDoc.table_create(rr)
|
SomeDoc.table_create(rr)
|
||||||
|
SomeDoc.table_ensure(rr)
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
SomeDoc.table_create(rr)
|
SomeDoc.table_create(rr)
|
||||||
|
|
||||||
@ -467,7 +468,7 @@ def test_orm_pk(rr):
|
|||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
NonstandardPrimaryKey.load(rr, 'no_such_thing')
|
NonstandardPrimaryKey.load(rr, 'no_such_thing')
|
||||||
|
|
||||||
NonstandardPrimaryKey.table_create(rr)
|
NonstandardPrimaryKey.table_ensure(rr)
|
||||||
|
|
||||||
# new empty doc
|
# new empty doc
|
||||||
f = NonstandardPrimaryKey(rr, {})
|
f = NonstandardPrimaryKey(rr, {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user