Skip to content

Commit

Permalink
Merge pull request #203 from maxtidev/develop
Browse files Browse the repository at this point in the history
Make creating indices idempotent
  • Loading branch information
moigagoo authored Jul 5, 2024
2 parents 18e09e9 + 9e35af8 commit ccac566
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/norm/postgres.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/norm/sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ccac566

Please sign in to comment.