File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ def db_schema(db_conn):
3939 db_conn .execute (
4040 """CREATE TABLE "hosts" (
4141 "id" integer PRIMARY KEY,
42- "ip" text,
42+ "ip" text UNIQUE ,
4343 "hostname" text,
4444 "domain" text,
4545 "os" text,
@@ -257,7 +257,7 @@ def add_host(
257257 # TODO: find a way to abstract this away to a single Upsert call
258258 q = Insert (self .HostsTable ) # .returning(self.HostsTable.c.id)
259259 update_columns = {col .name : col for col in q .excluded if col .name not in "id" }
260- q = q .on_conflict_do_update (index_elements = self . HostsTable . primary_key , set_ = update_columns )
260+ q = q .on_conflict_do_update (index_elements = [ "ip" ] , set_ = update_columns )
261261
262262 self .db_execute (q , hosts ) # .scalar()
263263 # we only return updated IDs for now - when RETURNING clause is allowed we can return inserted
You can’t perform that action at this time.
0 commit comments