9746: Remove duplicate columns in person table

This commit is contained in:
Nick Hall 2016-10-13 23:46:19 +01:00
parent 736b057706
commit a158c9cba8
3 changed files with 13 additions and 50 deletions

View File

@ -2231,13 +2231,12 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
""" """
return self.brief_name return self.brief_name
def get_person_data(self, person): def _get_person_data(self, person):
""" """
Given a Person, return primary_name.first_name, surname and gender. Given a Person, return primary_name.first_name and surname.
""" """
given_name = "" given_name = ""
surname = "" surname = ""
gender_type = Person.UNKNOWN
if person: if person:
primary_name = person.get_primary_name() primary_name = person.get_primary_name()
if primary_name: if primary_name:
@ -2247,8 +2246,7 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
surname_obj = surname_list[0] surname_obj = surname_list[0]
if surname_obj: if surname_obj:
surname = surname_obj.surname surname = surname_obj.surname
gender_type = person.gender return (given_name, surname)
return (given_name, surname, gender_type)
def set_default_person_handle(self, handle): def set_default_person_handle(self, handle):
self.set_metadata("default-person-handle", handle) self.set_metadata("default-person-handle", handle)

View File

@ -207,38 +207,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
for pr in self.person_ref_list] # 20 for pr in self.person_ref_list] # 20
} }
@classmethod
def field_aliases(cls):
"""
Return dictionary of alias to full field names
for this object class.
"""
return {
"given": "primary_name.first_name",
"surname": "primary_name.surname_list.0.surname",
"surnames": "primary_name.surname_list.surname",
"event.place": "event_ref_list.ref.place.name.value",
"event.year": "event_ref_list.ref.date.year",
}
@classmethod
def get_extra_secondary_fields(cls):
"""
Return a list of full field names and types for secondary
fields that are not directly listed in the schema.
"""
return [
("primary_name.first_name", str),
("primary_name.surname_list.0.surname", str),
]
@classmethod
def get_index_fields(cls):
return [
"primary_name.first_name",
"primary_name.surname_list.0.surname",
]
@classmethod @classmethod
def get_labels(cls, _): def get_labels(cls, _):
return { return {

View File

@ -183,7 +183,6 @@ class DBAPI(DbGeneric):
'handle VARCHAR(50) PRIMARY KEY NOT NULL, ' 'handle VARCHAR(50) PRIMARY KEY NOT NULL, '
'given_name TEXT, ' 'given_name TEXT, '
'surname TEXT, ' 'surname TEXT, '
'gender_type INTEGER, '
'order_by TEXT, ' 'order_by TEXT, '
'gramps_id TEXT, ' 'gramps_id TEXT, '
'blob_data BLOB' 'blob_data BLOB'
@ -488,12 +487,12 @@ class DBAPI(DbGeneric):
person AS mother person AS mother
on family.mother_handle = mother.handle on family.mother_handle = mother.handle
order by (case when father.handle is null order by (case when father.handle is null
then mother.primary_name__surname_list__0__surname then mother.surname
else father.primary_name__surname_list__0__surname else father.surname
end), end),
(case when family.handle is null (case when family.handle is null
then mother.primary_name__first_name then mother.given_name
else father.primary_name__first_name else father.given_name
end)) AS f;""") end)) AS f;""")
else: else:
self.dbapi.execute("SELECT handle FROM family;") self.dbapi.execute("SELECT handle FROM family;")
@ -734,36 +733,34 @@ class DBAPI(DbGeneric):
self._order_by_person_key(old_person)): self._order_by_person_key(old_person)):
self.remove_from_surname_list(old_person) self.remove_from_surname_list(old_person)
self.add_to_surname_list(person, trans.batch) self.add_to_surname_list(person, trans.batch)
given_name, surname, gender_type = self.get_person_data(person) given_name, surname = self._get_person_data(person)
# update the person: # update the person:
self.dbapi.execute("""UPDATE person SET gramps_id = ?, self.dbapi.execute("""UPDATE person SET gramps_id = ?,
order_by = ?, order_by = ?,
blob_data = ?, blob_data = ?,
given_name = ?, given_name = ?,
surname = ?, surname = ?
gender_type = ?
WHERE handle = ?;""", WHERE handle = ?;""",
[person.gramps_id, [person.gramps_id,
self._order_by_person_key(person), self._order_by_person_key(person),
pickle.dumps(person.serialize()), pickle.dumps(person.serialize()),
given_name, given_name,
surname, surname,
gender_type,
person.handle]) person.handle])
else: else:
self.genderStats.count_person(person) self.genderStats.count_person(person)
self.add_to_surname_list(person, trans.batch) self.add_to_surname_list(person, trans.batch)
given_name, surname, gender_type = self.get_person_data(person) given_name, surname = self._get_person_data(person)
# Insert the person: # Insert the person:
self.dbapi.execute( self.dbapi.execute(
"""INSERT INTO person (handle, order_by, gramps_id, blob_data, """INSERT INTO person (handle, order_by, gramps_id, blob_data,
given_name, surname, gender_type) given_name, surname)
VALUES(?, ?, ?, ?, ?, ?, ?);""", VALUES(?, ?, ?, ?, ?, ?);""",
[person.handle, [person.handle,
self._order_by_person_key(person), self._order_by_person_key(person),
person.gramps_id, person.gramps_id,
pickle.dumps(person.serialize()), pickle.dumps(person.serialize()),
given_name, surname, gender_type]) given_name, surname])
self.update_secondary_values(person) self.update_secondary_values(person)
if not trans.batch: if not trans.batch:
self.update_backlinks(person) self.update_backlinks(person)