From 015b445c3b1b6abe5756f5100a7668f686af7eb8 Mon Sep 17 00:00:00 2001 From: Max T <163015439+maxtidev@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:26:27 +0200 Subject: [PATCH 1/2] Make creating indices idempotent (postgres) --- src/norm/postgres.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/norm/postgres.nim b/src/norm/postgres.nim index 2e16cfe0..f98186c3 100644 --- a/src/norm/postgres.nim +++ b/src/norm/postgres.nim @@ -159,14 +159,14 @@ proc createTables*[T: Model](dbConn; obj: T) = dbConn.exec(sql qry) for index, cols in indexes.pairs: - let qry = "CREATE INDEX $# ON $#($#);" % [index, T.table, cols.join(", ")] + let qry = "CREATE INDEX IF NOT EXISTS $# ON $#($#);" % [index, T.table, cols.join(", ")] log(qry) dbConn.exec(sql qry) for index, cols in uniqueIndexes.pairs: - let qry = "CREATE UNIQUE INDEX $# ON $#($#);" % [index, T.table, cols.join(", ")] + let qry = "CREATE UNIQUE INDEX IF NOT EXISTS $# ON $#($#);" % [index, T.table, cols.join(", ")] log(qry) From 9e35af83545d6e240aa1a869b366f9a7b6ad575b Mon Sep 17 00:00:00 2001 From: Max T <163015439+maxtidev@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:27:34 +0200 Subject: [PATCH 2/2] Make creating indices idempotent (sqlite) --- src/norm/sqlite.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/norm/sqlite.nim b/src/norm/sqlite.nim index b89c737d..04716bac 100644 --- a/src/norm/sqlite.nim +++ b/src/norm/sqlite.nim @@ -146,14 +146,14 @@ proc createTables*[T: Model](dbConn; obj: T) = dbConn.exec(sql qry) for index, cols in indexes.pairs: - let qry = "CREATE INDEX $# ON $#($#);" % [index, T.table, cols.join(", ")] + let qry = "CREATE INDEX IF NOT EXISTS $# ON $#($#);" % [index, T.table, cols.join(", ")] log(qry) dbConn.exec(sql qry) for index, cols in uniqueIndexes.pairs: - let qry = "CREATE UNIQUE INDEX $# ON $#($#);" % [index, T.table, cols.join(", ")] + let qry = "CREATE UNIQUE INDEX IF NOT EXISTS $# ON $#($#);" % [index, T.table, cols.join(", ")] log(qry)