Database corruption
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
Association.allInstances-> | Association.allInstances-> | ||
select(a|a.Class.notNull and a.Class.isPersistent)-> | |||
collect(a|a.Class.Name, | |||
let ae = a.AssociationEnd->at(1) in | |||
let c1 = ae.Participant in | |||
if c1.TaggedValue->exists(tv | (tv.Tag='Eco.TableMapping') and (tv.Value = 'Parent')) then | |||
c1.Superclass.Name | |||
else | |||
c1.Name | |||
endif->collect(classname|if classname='User' then 'User_TBL' else classname endif)->first, | |||
let ae = a.AssociationEnd->at(1) in | |||
ae.Name, | |||
let ae = a.AssociationEnd->at(1) in | |||
ae.TaggedValue->select(tv | tv.Tag='Eco.InnerLinkName')->first.Value, | |||
let ae = a.AssociationEnd->at(2) in | |||
let c1 = ae.Participant in | |||
if c1.TaggedValue->exists(tv | (tv.Tag='Eco.TableMapping') and (tv.Value = 'Parent')) then | |||
c1.Superclass.Name | |||
else | |||
c1.Name | |||
endif->collect(classname|if classname='User' then 'User_TBL' else classname endif)->first, | |||
let ae = a.AssociationEnd->at(2) in | |||
ae.Name, | |||
let ae = a.AssociationEnd->at(2) in | |||
ae.TaggedValue->select(tv | tv.Tag='Eco.InnerLinkName')->first.Value | |||
)->orderBy(x|x.Name)-> | )->orderBy(x|x.Name)-> | ||
collect(d | | |||
collect(d | | |||
'select * from ' + d.Name + ' where ' + if d.Part4.isNullOrEmpty then d.Part3 else d.Part4 endif + 'ID not in (select ' + d.Part2 + 'ID from ' + d.Part2 + ')\r\n'+ | 'select * from ' + d.Name + ' where ' + if d.Part4.isNullOrEmpty then d.Part3 else d.Part4 endif + 'ID not in (select ' + d.Part2 + 'ID from ' + d.Part2 + ')\r\n'+ | ||
'select * from ' + d.Name + ' where ' + if d.Part7.isNullOrEmpty then d.Part6 else d.Part7 endif + 'ID not in (select ' + d.Part5 + 'ID from ' + d.Part5 + ')' | 'select * from ' + d.Name + ' where ' + if d.Part7.isNullOrEmpty then d.Part6 else d.Part7 endif + 'ID not in (select ' + d.Part5 + 'ID from ' + d.Part5 + ')' | ||
)->asSeparatedList('\r\n') | )->asSeparatedList('\r\n') |
Revision as of 12:52, 12 August 2020
An inconsistent database is a rare thing when using MDriven Server and Turnkey.
But it can happen, and if it happens it's almost always because of an evolve that went wrong somehow and objects was left behind.
Especially problematic is link-classes with incorrect link information. Because link-objects only can exist when the two connected objects exist, they can't even be loaded into memory.
So, this needs to be corrected at the sql server level.
But, as an MDriven user we really don't want to spend any time on SQL-related things, so, in order to create the SQL that looks up problems, we can use the model debugger on the model itself.
Association.allInstances-> select(a|a.Class.notNull and a.Class.isPersistent)-> collect(a|a.Class.Name, let ae = a.AssociationEnd->at(1) in let c1 = ae.Participant in if c1.TaggedValue->exists(tv | (tv.Tag='Eco.TableMapping') and (tv.Value = 'Parent')) then c1.Superclass.Name else c1.Name endif->collect(classname|if classname='User' then 'User_TBL' else classname endif)->first, let ae = a.AssociationEnd->at(1) in ae.Name, let ae = a.AssociationEnd->at(1) in ae.TaggedValue->select(tv | tv.Tag='Eco.InnerLinkName')->first.Value, let ae = a.AssociationEnd->at(2) in let c1 = ae.Participant in if c1.TaggedValue->exists(tv | (tv.Tag='Eco.TableMapping') and (tv.Value = 'Parent')) then c1.Superclass.Name else c1.Name endif->collect(classname|if classname='User' then 'User_TBL' else classname endif)->first, let ae = a.AssociationEnd->at(2) in ae.Name, let ae = a.AssociationEnd->at(2) in ae.TaggedValue->select(tv | tv.Tag='Eco.InnerLinkName')->first.Value )->orderBy(x|x.Name)-> collect(d | 'select * from ' + d.Name + ' where ' + if d.Part4.isNullOrEmpty then d.Part3 else d.Part4 endif + 'ID not in (select ' + d.Part2 + 'ID from ' + d.Part2 + ')\r\n'+ 'select * from ' + d.Name + ' where ' + if d.Part7.isNullOrEmpty then d.Part6 else d.Part7 endif + 'ID not in (select ' + d.Part5 + 'ID from ' + d.Part5 + ')' )->asSeparatedList('\r\n')
This page was edited more than 9 months ago on 03/26/2024. What links here