2006-08-15 Alex Roitman <shura@gramps-project.org>

* src/GrampsDb/_GrampsBSDDB.py: Cleanup on upgrades.



svn: r7181
This commit is contained in:
Alex Roitman 2006-08-15 15:33:28 +00:00
parent 244300257d
commit 617116064f
2 changed files with 64 additions and 79 deletions

View File

@ -1,3 +1,6 @@
2006-08-15 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py: Cleanup on upgrades.
2006-08-14 Alex Roitman <shura@gramps-project.org> 2006-08-14 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_10): Add an upgrade * src/GrampsDb/_GrampsBSDDB.py (gramps_upgrade_10): Add an upgrade
path from 2.1.91. path from 2.1.91.

View File

@ -1403,7 +1403,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.gramps_upgrade_8() self.gramps_upgrade_8()
if version < 9: if version < 9:
self.gramps_upgrade_9() self.gramps_upgrade_9()
if version < 10: elif version < 10:
self.gramps_upgrade_10() self.gramps_upgrade_10()
print "Upgrade time:", int(time.time()-t), "seconds" print "Upgrade time:", int(time.time()-t), "seconds"
@ -1487,11 +1487,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.metadata.sync() self.metadata.sync()
def gramps_upgrade_9(self): def gramps_upgrade_9(self):
print "Upgrading to DB version 9 -- this may take a while" print "Upgrading to DB version 10 -- this may take a while"
# The very very first thing is to check for duplicates in the # The very very first thing is to check for duplicates in the
# primary tables and remove them. # primary tables and remove them.
self.set_total(7) self.set_total(7)
status,length = low_level_9(self,self.update) status,length = low_level_9(self,self.update)
self.reset()
self.set_total(length) self.set_total(length)
@ -1760,10 +1761,13 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
event = Event() event = Event()
event.handle = handle event.handle = handle
(junk_handle, event.gramps_id, old_type, event.date, (junk_handle, event.gramps_id, old_type, event.date,
event.description, event.place, event.cause, event.private, event.description, event.place, cause, event.private,
event.source_list, event.note, witness_list, event.source_list, event.note, witness_list,
event.media_list, event.change) = info event.media_list, event.change) = info
if event.source_list != []:
print [sr.serialize() for sr in event.source_list]
# Change ID if it is non-unique # Change ID if it is non-unique
if event.gramps_id in dup_ids: if event.gramps_id in dup_ids:
max_id_number += 1 max_id_number += 1
@ -1810,6 +1814,13 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
"while upgrading database to version 9.") "while upgrading database to version 9.")
event.set_note(note_text) event.set_note(note_text)
# This is an upgrade_10 step
if cause.strip():
attr = Attribute()
attr.set_type(AttributeType.CAUSE)
attr.set_value(cause)
event.add_attribute(attr)
self.commit_event(event,trans) self.commit_event(event,trans)
self.update() self.update()
@ -1859,13 +1870,13 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
the_txn = self.env.txn_begin() the_txn = self.env.txn_begin()
else: else:
the_txn = None the_txn = None
self.metadata.put('version',9,txn=the_txn) self.metadata.put('version',10,txn=the_txn)
if self.UseTXN: if self.UseTXN:
the_txn.commit() the_txn.commit()
else: else:
self.metadata.sync() self.metadata.sync()
print "Done upgrading to DB version 9" print "Done upgrading to DB version 10"
def gramps_upgrade_10(self): def gramps_upgrade_10(self):
print "Upgrading to DB version 10 -- this may take a while" print "Upgrading to DB version 10 -- this may take a while"
@ -1885,37 +1896,26 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
# so starting (batch) transaction here. # so starting (batch) transaction here.
trans = self.transaction_begin("",True) trans = self.transaction_begin("",True)
# Import secondary modules from RelLib
from RelLib._DateBase import DateBase
from RelLib._MediaBase import MediaBase
from RelLib._SourceBase import SourceBase
from RelLib._NoteBase import NoteBase
from RelLib._LdsOrdBase import LdsOrdBase
from RelLib._AddressBase import AddressBase
from RelLib._AttributeBase import AttributeBase
from RelLib._UrlBase import UrlBase
from RelLib._PrivacyBase import PrivacyBase
from RelLib._RefBase import RefBase
# This upgrade adds attribute lists to Event and EventRef objects # This upgrade adds attribute lists to Event and EventRef objects
self.set_total(self.get_number_of_events()) length = self.get_number_of_events() + len(self.person_map) \
+ self.get_number_of_families()
self.set_total(length)
for handle in self.event_map.keys(): for handle in self.event_map.keys():
info = self.event_map[handle] info = self.event_map[handle]
(junk_handle, gramps_id, the_type, date,description,
place, cause,source_list, note, media_list,
change, marker, private) = info
new_info = (handle, gramps_id, the_type, date,
description, place, source_list, note, media_list,
[], change, marker, private)
event = Event() event = Event()
event.handle = handle event.unserialize(new_info)
(junk_handle, event.gramps_id, the_type, date,
event.description, event.place, cause,
source_list, note, media_list,
event.change, marker, event.private) = info
event.marker.unserialize(marker)
event.type.unserialize(the_type)
DateBase.unserialize(event,date)
MediaBase.unserialize(event,media_list)
SourceBase.unserialize(event,source_list)
NoteBase.unserialize(event,note)
# Cause is removed, so we're converting it into an attribute
if cause.strip(): if cause.strip():
attr = Attribute() attr = Attribute()
attr.set_type(AttributeType.CAUSE) attr.set_type(AttributeType.CAUSE)
@ -1924,75 +1924,57 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
self.commit_event(event,trans) self.commit_event(event,trans)
self.update() self.update()
self.reset()
# Personal event references # Personal event references
self.set_total(len(self.person_map))
for handle in self.person_map.keys(): for handle in self.person_map.keys():
info = self.person_map[handle] info = self.person_map[handle]
person = Person()
person.handle = handle
(junk_handle,person.gramps_id,person.gender,
primary_name,alternate_names,person.death_ref_index,
person.birth_ref_index,event_ref_list,person.family_list,
person.parent_family_list,media_list,address_list,attribute_list,
urls,lds_ord_list,source_list,note,person.change,marker,
person.private,person_ref_list,) = info
person.marker.unserialize(marker) (junk_handle,gramps_id,gender,
person.primary_name.unserialize(primary_name) primary_name,alternate_names,death_ref_index,
person.alternate_names = [Name().unserialize(name) birth_ref_index,event_ref_list,family_list,
for name in alternate_names] parent_family_list,media_list,address_list,attribute_list,
person.person_ref_list = [PersonRef().unserialize(pr) urls,lds_ord_list,source_list,note,change,marker,
for pr in person_ref_list] private,person_ref_list,) = info
MediaBase.unserialize(person, media_list)
LdsOrdBase.unserialize(person, lds_ord_list) new_info = (handle,gramps_id,gender,primary_name,alternate_names,
AddressBase.unserialize(person, address_list) death_ref_index,birth_ref_index,[],
AttributeBase.unserialize(person, attribute_list) family_list,parent_family_list,media_list,address_list,
UrlBase.unserialize(person, urls) attribute_list,urls,lds_ord_list,source_list,note,
SourceBase.unserialize(person, source_list) change,marker,private,person_ref_list,)
NoteBase.unserialize(person, note)
person = Person()
person.unserialize(new_info)
for (privacy,note,ref,role) in event_ref_list: for (privacy,note,ref,role) in event_ref_list:
event_ref = EventRef() event_ref = EventRef()
PrivacyBase.unserialize(event_ref,privacy) new_event_ref_data = (privacy,note,[],ref,role)
NoteBase.unserialize(event_ref,note) event_ref.unserialize(new_event_ref_data)
RefBase.unserialize(event_ref,ref)
event_ref.role.unserialize(role)
person.add_event_ref(event_ref) person.add_event_ref(event_ref)
self.commit_person(person,trans) self.commit_person(person,trans)
self.update() self.update()
self.reset()
# Family event references # Family event references
self.set_total(self.get_number_of_families())
for handle in self.family_map.keys(): for handle in self.family_map.keys():
info = self.family_map[handle] info = self.family_map[handle]
family = Family()
family.handle = handle
(junk_handle,family.gramps_id,family.father_handle, (junk_handle,gramps_id,father_handle,
family.mother_handle,child_ref_list,the_type,event_ref_list, mother_handle,child_ref_list,the_type,event_ref_list,
media_list,attribute_list,lds_seal_list,source_list,note, media_list,attribute_list,lds_seal_list,source_list,note,
family.change, marker, family.private) = info change, marker, private) = info
family.marker.unserialize(marker) new_info = (handle,gramps_id,father_handle,
family.type.unserialize(the_type) mother_handle,child_ref_list,the_type,[],
family.child_ref_list = [ChildRef().unserialize(cr) media_list,attribute_list,lds_seal_list,
for cr in child_ref_list] source_list,note,change, marker, private)
MediaBase.unserialize(family,media_list)
AttributeBase.unserialize(family,attribute_list) family = Family()
SourceBase.unserialize(family,source_list) family.unserialize(new_info)
NoteBase.unserialize(family,note)
LdsOrdBase.unserialize(family,lds_seal_list)
for (privacy,note,ref,role) in event_ref_list: for (privacy,note,ref,role) in event_ref_list:
event_ref = EventRef() event_ref = EventRef()
PrivacyBase.unserialize(event_ref,privacy) new_event_ref_data = (privacy,note,[],ref,role)
NoteBase.unserialize(event_ref,note) event_ref.unserialize(new_event_ref_data)
RefBase.unserialize(event_ref,ref)
event_ref.role.unserialize(role)
family.add_event_ref(event_ref) family.add_event_ref(event_ref)
self.commit_family(family,trans) self.commit_family(family,trans)