Skip to content

Commit

Permalink
Refactor harvest models
Browse files Browse the repository at this point in the history
Use the declarative way, and inherit from `BaseModel` in the toolkit,
so tables get properly created and dropped in tests
  • Loading branch information
amercader committed Jun 25, 2024
1 parent 2614432 commit 0c5da80
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 213 deletions.
10 changes: 3 additions & 7 deletions ckanext/harvest/harvesters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,11 @@ def _create_or_update_package(self, package_dict, harvest_object,
return 'unchanged'

# Flag the other objects linking to this package as not current anymore
from ckanext.harvest.model import harvest_object_table
conn = Session.connection()
u = update(harvest_object_table)\
.where(harvest_object_table.c.package_id == bindparam('b_package_id')) \
.values(current=False)
conn.execute(u, b_package_id=new_package['id'])
Session.query(HarvestObject).filter(
HarvestObject.package_id == new_package["id"]).update(
{"current": False})

# Flag this as the current harvest object

harvest_object.package_id = new_package['id']
harvest_object.current = True
harvest_object.save()
Expand Down
Loading

0 comments on commit 0c5da80

Please sign in to comment.