consitent vs peformance database design for db polymorphism with versioning
I need to create a database for 2 types of farmers (organizations and landlords) which have different columns that need to be stored and I also need to version their info.
One db design that I came up with is this: (the consistent one)
Farmers
Id
FType check(FType in ('organization', 'landlord'))
Unique(Id,Ftype)
Organizations
Id
FType
Unique(Id, FType)
FK(Id, FType) Ref Farmers(Id, FType)
LandLords
Id
FType
Unique(Id, FType)
FK(Id, FType) Ref Farmers(Id, FType)
OrganisationVersions
Id
OrganisationId ref Organizations(id)
--lots of stuff specific to organisation
Startdate
Endate -- if null than this is the current version
LandLordVersions
Id
LandLordId ref LandLords(id)
--lots of stuff specific to landlord
StartDate
EndDate
The second one not so consistent but much less tables is like this:
Farmers
Id
FType
Organi开发者_如何学Gozations
Id
FarmerId ref Farmers(Id)
--stuff
StartDate
EndDate -- if null than this is the current version
LandLords
Id
FarmerId ref Farmers(Id)
--stuff
StartDate
EndDate
I don't see any especial difficulties with your second version. The first version has an FType column in the Organisations table and the Landlords table, which doesn't seem to be necessary as it will be the same for all rows.
Having multiple versions of each entry in the same table, with the latest end date as NULL for the current version also seems fine; you could create a view 'Current_Landlords' where only the current row is displayed; such a view would be updatable. Some indexes might be necessary to help it out.
精彩评论