Update extra columns on existing rows
This commit is contained in:
parent
2665e56e6f
commit
faf4770c5d
|
@ -73,11 +73,25 @@ class HaveData(Node):
|
|||
self.result = csr.fetchall()
|
||||
log_check.info("Got %d rows", len(self.result))
|
||||
if self.result:
|
||||
extra_columns = list(self.extra.keys())
|
||||
for c in extra_columns:
|
||||
if self.result[0][c] != self.extra[c]:
|
||||
log_action.info("Updating %s: %s <- %s", key_values, c, self.extra[c])
|
||||
q = sql.SQL(
|
||||
"update {table} set {column}={placeholder} where {key_check}"
|
||||
).format(
|
||||
table=sql.Identifier(self.table),
|
||||
column=sql.Identifier(c),
|
||||
placeholder=sql.Placeholder(),
|
||||
key_check=key_check,
|
||||
)
|
||||
csr.execute(q, [self.extra[c]] + key_values)
|
||||
self.result[0][c] = self.extra[c]
|
||||
self.set_order()
|
||||
self.ok = True
|
||||
log_state.info("%s is now ok", self.name)
|
||||
return
|
||||
|
||||
else:
|
||||
extra_values = [v.resolve() if isinstance(v, Ref) else v for v in self.extra.values()]
|
||||
columns = list(self.key.keys()) + list(self.extra.keys())
|
||||
values = key_values + extra_values
|
||||
|
|
Loading…
Reference in New Issue