"unarchive" a record?

51 views
Skip to first unread message

jim kaubisch

unread,
Jun 11, 2018, 4:49:46 PM6/11/18
to web2py-users
Hi,

I'm probably missing something obvious since I don't see anyone asking this but here it goes...

I want to archive a db record but, at a later date, I may want to unarchive it, i.e. make it current again and I'm not sure I understand how to do that coherently 

 - I have record versioning enabled 
 - I can see that when I "delete" a record in table "abc", its "is_active" field is set to False and the abc_archive table gets a new entry for the deleted record

But, if I now want to reverse the process, i.e. make the record current, what do I need to do (and leave the db in a state where, if I later re-archive that record, things are consistent? )
  - Only set "is_active" to true? 
  - What about the records in the archive table? Delete/modify those records? - if I later re-archive that record, I need things to be consistent

Ideally, I'd like a ongoing modification history
 - record was originally created 3 years ago, archived last year, re-activated 3 months ago and re-archived yesterday...

Thanks,
Jim


Leonel Câmara

unread,
Jun 12, 2018, 5:28:32 AM6/12/18
to web2py-users
Say you have a table named "record" with a name and a description field and you want to revert to the version with record_archive ID given in request.args(0)


version
= db.record_archive[request.args(0)]
current
= db.record[version.current_record]
current
.update_record(name=version.name, description=version.description)



Anthony

unread,
Jun 12, 2018, 12:43:15 PM6/12/18
to web2py-users
But, if I now want to reverse the process, i.e. make the record current, what do I need to do (and leave the db in a state where, if I later re-archive that record, things are consistent? )
  - Only set "is_active" to true?

Yes, I think that should do it (note, when you do that, it should automatically archive the current "deleted" version -- i.e., the version with in_active=False).
 
  - What about the records in the archive table? Delete/modify those records? - if I later re-archive that record, I need things to be consistent

I don't think you should have to touch the archive table. Whenever a change is made in the original table (including setting is_active to False or back to True), the current version of the record is archived (before the change is made). So, the archive table should have a record of all previous states.
 
Ideally, I'd like a ongoing modification history
 - record was originally created 3 years ago, archived last year, re-activated 3 months ago and re-archived yesterday...

If the table includes a modified_on timestamp (e.g., via auth.signature), then you should be able to query all records in the archive table that reference the current record in the original table and sort by modification date to view the history of previous states (including alternating values of is_active).

Anthony

Anthony

unread,
Jun 12, 2018, 12:45:46 PM6/12/18
to web2py-users
current.update_record(name=version.name, description=version.description)


And note, if you have a lot of fields to update, the above can be simplified to:

current.update_record(**db.record._filter_fields(version))

Anthony

jim kaubisch

unread,
Jun 18, 2018, 11:10:32 PM6/18/18
to web2py-users
Thanks for your inputs. Used it, checked to make sure the results were as I expected them to be. Good progress on this since then...
Reply all
Reply to author
Forward
0 new messages