You could link DmgState to RiskCalculation instead of OqJob. So, damage states (that are actually got by configuration files are not repeated when the fragility models do not change across jobs). Here, you should use get_or_create instead of always performing an insert