Skip to content

Commit

Permalink
Merge pull request #193 from VForWaTer/details_adjustments
Browse files Browse the repository at this point in the history
Details adjustments
  • Loading branch information
AlexDo1 authored Dec 16, 2022
2 parents 5fc68a2 + e27b043 commit 024ab3d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion metacatalog/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.1'
__version__ = '0.6.2'
2 changes: 2 additions & 0 deletions metacatalog/db/revisions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
rev9,
rev10,
rev11,
rev12,
)

revisions = {
Expand All @@ -26,4 +27,5 @@
9: rev9,
10: rev10,
11: rev11,
12: rev12,
}
48 changes: 48 additions & 0 deletions metacatalog/db/revisions/rev12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Metacatalog database revision
-----------------------------
date: 2022-12-16T17:43:29.087342
revision #12
Details adjustments:
- Details.key has now a limit of 60 letters (instead of 20)
- new column Details.title
"""
from sqlalchemy.orm import Session
from metacatalog import api, models

UPGRADE_SQL = """
-- details.key 60 letters limit
ALTER TABLE details ALTER COLUMN key TYPE varchar(60);
COMMIT;
-- create column details.title
ALTER TABLE details ADD COLUMN title VARCHAR;
COMMIT;
"""

DOWNGRADE_SQL = """
-- details.key 20 letters limit, shorten key if longer than 20 letters
UPDATE details SET key=LEFT(key, 20);
ALTER TABLE details ALTER COLUMN key TYPE varchar(20);
COMMIT;
-- delete column details.title
ALTER TABLE details DROP COLUMN title;
COMMIT;
"""

# define the upgrade function
def upgrade(session: Session):
print('run update')
# details key letter limit 60 and new column title
with session.bind.connect() as con:
con.execute(UPGRADE_SQL)


# define the downgrade function
def downgrade(session: Session):
print('run downgrade')
# details key letter limit 20 and drop column title
with session.bind.connect() as con:
con.execute(DOWNGRADE_SQL)
13 changes: 12 additions & 1 deletion metacatalog/models/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ class Detail(Base):
key : str
The key of the key vaule par. Maximum 20 letters,
ideally no whitespaces.
.. versionchanged:: 0.6.2
Maximum letters changed from 20 to 60.
Ideally, the key should come from a thesaurus available in the
database. In this case, also link the detail to the thesaurus
via :attr:`thesaurus_id`.
stem : str
Stemmed key using a `nltk.PorterStemmer`. The stemmed
key can be used to search for related keys
title : str
.. versionadded:: 0.6.2
Optional longer and more descriptive title than :attr:`key`,
use this field e.g. if you used a thesaurus for attr:`key`, but
a longer or more precise title provides additional information.
value : str, list
.. versionchanged:: 0.3.0
The actual value of this detail. This can be a string
Expand Down Expand Up @@ -72,8 +82,9 @@ class Detail(Base):
# columns
id = Column(Integer, primary_key=True, autoincrement=True)
entry_id = Column(Integer, ForeignKey('entries.id'))
key = Column(String(20), nullable=False)
key = Column(String(60), nullable=False)
stem = Column(String(20), nullable=False)
title = Column(String, nullable=True)
raw_value = Column(MutableDict.as_mutable(JSONB), nullable=False)
description = Column(String, nullable=True)
thesaurus_id = Column(Integer, ForeignKey('thesaurus.id'))
Expand Down

0 comments on commit 024ab3d

Please sign in to comment.