Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:OnroerendErfgoed/skosprovider_sq…
Browse files Browse the repository at this point in the history
…lalchemy into develop

* 'develop' of github.com:OnroerendErfgoed/skosprovider_sqlalchemy:
  Change concept.concept_id from int to str. (#91)
  • Loading branch information
koenedaele committed Jan 3, 2023
2 parents bb8e917 + 08a7549 commit 26754e8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 71 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ A SQLAlchemy implementation of the skosprovider_ interface.
:target: https://coveralls.io/r/koenedaele/skosprovider_sqlalchemy


Migrating to skosprovider_sqlalchemy 2.0.0
------------------------------------------
A change in the models has been made which requires a database upgrade.
The "concept" table's "concept_id" column has changed from being an int to a string.

Existing databases will therefor require a small change to update table scheme.
Typically this will look like::

ALTER TABLE concept ALTER COLUMN concept_id TEXT NOT NULL;


Building the docs
-----------------

Expand Down
2 changes: 1 addition & 1 deletion skosprovider_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Thing(Base):
id = Column(Integer, primary_key=True)
type = Column(String(30))
concept_id = Column(
Integer,
String,
nullable=False,
index=True
)
Expand Down
8 changes: 4 additions & 4 deletions skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ def _from_thing(self, thing):
matches=matches
)

def get_by_id(self, id):
def get_by_id(self, concept_id):
try:
thing = self.session\
.query(Thing)\
.options(joinedload('labels'))\
.options(joinedload('notes'))\
.options(joinedload('sources'))\
.filter(
Thing.concept_id == int(id),
Thing.concept_id == str(concept_id),
Thing.conceptscheme_id == self.conceptscheme_id
).one()
except NoResultFound:
Expand Down Expand Up @@ -328,7 +328,7 @@ def expand(self, id):
thing = self.session\
.query(Thing)\
.filter(
Thing.concept_id == id,
Thing.concept_id == str(id),
Thing.conceptscheme_id == self.conceptscheme_id
).one()
except NoResultFound:
Expand Down Expand Up @@ -428,7 +428,7 @@ def get_children_display(self, id, **kwargs):
thing = self.session\
.query(Thing)\
.filter(
Thing.concept_id == int(id),
Thing.concept_id == str(id),
Thing.conceptscheme_id == self.conceptscheme_id
).one()
except NoResultFound:
Expand Down
12 changes: 6 additions & 6 deletions skosprovider_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def import_provider(provider, conceptscheme, session):
if isinstance(c, Concept):
cm = session.query(ConceptModel) \
.filter(ConceptModel.conceptscheme_id == conceptscheme.id) \
.filter(ConceptModel.concept_id == int(c.id)) \
.filter(ConceptModel.concept_id == str(c.id)) \
.one()
if len(c.narrower) > 0:
for nc in c.narrower:
try:
nc = session.query(ConceptModel) \
.filter(ConceptModel.conceptscheme_id == conceptscheme.id) \
.filter(ConceptModel.concept_id == int(nc)) \
.filter(ConceptModel.concept_id == str(nc)) \
.one()
cm.narrower_concepts.add(nc)
except NoResultFound:
Expand All @@ -94,7 +94,7 @@ def import_provider(provider, conceptscheme, session):
try:
sa = session.query(CollectionModel) \
.filter(CollectionModel.conceptscheme_id == conceptscheme.id) \
.filter(CollectionModel.concept_id == int(sa)) \
.filter(CollectionModel.concept_id == str(sa)) \
.one()
cm.narrower_collections.add(sa)
except NoResultFound:
Expand All @@ -106,7 +106,7 @@ def import_provider(provider, conceptscheme, session):
try:
rc = session.query(ConceptModel) \
.filter(ConceptModel.conceptscheme_id == conceptscheme.id) \
.filter(ConceptModel.concept_id == int(rc)) \
.filter(ConceptModel.concept_id == str(rc)) \
.one()
cm.related_concepts.add(rc)
except NoResultFound:
Expand All @@ -116,13 +116,13 @@ def import_provider(provider, conceptscheme, session):
elif isinstance(c, Collection) and len(c.members) > 0:
cm = session.query(CollectionModel) \
.filter(ConceptModel.conceptscheme_id == conceptscheme.id) \
.filter(ConceptModel.concept_id == int(c.id)) \
.filter(ConceptModel.concept_id == str(c.id)) \
.one()
for mc in c.members:
try:
mc = session.query(ThingModel) \
.filter(ConceptModel.conceptscheme_id == conceptscheme.id) \
.filter(ConceptModel.concept_id == int(mc)) \
.filter(ConceptModel.concept_id == str(mc)) \
.one()
cm.members.add(mc)
except NoResultFound:
Expand Down
Loading

0 comments on commit 26754e8

Please sign in to comment.