"update templates_history t set updated_at = (select updated_at from templates_history th where t.version = th.version -1 and t.id = th.id and t.version != 1)"
)
op.execute(
"update templates_history th set updated_at = (select t.updated_at from templates_history h, templates t where h.id = t.id and h.version = t.version and th.id = h.id) where (th.id, th.version) = (select t.id, t.version from templates t where t.id = th.id and t.version = th.version)"