Skip to content

Commit

Permalink
models: versioning support
Browse files Browse the repository at this point in the history
* Uses SQLAlchemy-Continuum to provide full versioning support.

Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
  • Loading branch information
jirikuncar committed Oct 22, 2015
1 parent d0999e7 commit e64a97e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
15 changes: 15 additions & 0 deletions invenio_records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@

"""Record models."""

import pkg_resources

from invenio_db import db
from sqlalchemy_continuum import make_versioned
from sqlalchemy_utils.models import Timestamp
from sqlalchemy_utils.types import JSONType

try:
pkg_resources.get_distribution('invenio_accounts')
except pkg_resources.DistributionNotFound:
user_cls = None
else:
from invenio_accounts.models import User as user_cls

make_versioned(user_cls=user_cls)


class Record(db.Model, Timestamp):
"""Represent a record metadata inside the SQL database.
Expand All @@ -36,6 +48,9 @@ class Record(db.Model, Timestamp):
with automatically managed timestamps.
"""

# Enables SQLAlchemy-Continuum versioning
__versioned__ = {}

__tablename__ = 'record'

id = db.Column(
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
tests_require = [
'check-manifest>=0.25',
'coverage>=4.0',
'invenio-db[all]>=1.0.0a3',
'invenio-db[all]>=1.0.0a4',
'isort>=4.2.2',
'pep257>=0.7.0',
'pytest-cache>=1.0',
Expand All @@ -64,9 +64,10 @@
install_requires = [
'blinker>=1.4',
'flask-celeryext>=0.1.0',
'invenio-db>=1.0.0a3',
'invenio-db>=1.0.0a4',
'jsonpatch>=1.11',
'jsonschema>=2.5.1',
'sqlalchemy-continuum>=1.2.1',
'sqlalchemy-utils>=0.31.0',
]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_invenio_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_db():
with app.app_context():
create_database(db.engine.url)
db.create_all()
assert len(db.metadata.tables) == 1
assert len(db.metadata.tables) == 3

data = {'recid': 1, 'title': 'Test'}
from invenio_records.models import Record as RM
Expand Down Expand Up @@ -150,7 +150,7 @@ def test_cli():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)

assert len(db.metadata.tables) == 1
assert len(db.metadata.tables) == 3

# Test merging a base another file.
with runner.isolated_filesystem():
Expand Down

0 comments on commit e64a97e

Please sign in to comment.