Skip to content

Commit dfbd920

Browse files
committed
Added ON CONFLICT, now does upsert
1 parent 3bec35c commit dfbd920

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/server/api/admin_api.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from datetime import datetime
55
import json
66
from sqlalchemy.sql import text
7+
8+
from sqlalchemy.dialects.postgresql import insert
79
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, exc, select
810
from pipeline import flow_script
911
from config import engine
@@ -72,12 +74,17 @@ def execute():
7274
last_ex_json = (json.dumps(last_execution_details))
7375

7476
with engine.connect() as connection:
75-
ins_stmt = kvt.insert().values(
77+
ins_stmt = insert(kvt).values(
7678
keycol = 'last_execution_time',
7779
valcol = last_ex_json,
80+
)
81+
82+
upsert = ins_stmt.on_conflict_do_update(
83+
constraint='kv_unique_keycol_key',
84+
set_=dict(valcol=last_ex_json)
7885
)
7986

80-
connection.execute(ins_stmt)
87+
connection.execute(upsert)
8188

8289

8390
return jsonify(success=True)

0 commit comments

Comments
 (0)