Skip to content

Commit

Permalink
Use binders for setting parameters in SQLCodeMigrations
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Apr 18, 2024
1 parent 6a6dd77 commit 1896a96
Showing 1 changed file with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,75 @@ object SQLCodeMigrations {
val newFeedId = nameBasedUuidOf(oldFeedId).toString()
driver.execute(
identifier = null,
sql = "UPDATE feed SET id = '$newFeedId' WHERE id = '$oldFeedId'",
parameters = 0,
binders = null
sql = "UPDATE feed SET id = ? WHERE id = ?",
parameters = 2,
binders = {
bindString(0, newFeedId)
bindString(1, oldFeedId)
}
)

driver.execute(
identifier = null,
sql = "UPDATE feed_search SET id = '$newFeedId' WHERE id = '$oldFeedId'",
parameters = 0,
binders = null
sql = "UPDATE feed_search SET id = ? WHERE id = ?",
parameters = 2,
binders = {
bindString(0, newFeedId)
bindString(1, oldFeedId)
}
)

driver.execute(
identifier = null,
sql = "UPDATE bookmark SET sourceId = '$newFeedId' WHERE sourceId = '$oldFeedId'",
parameters = 0,
binders = null
sql = "UPDATE bookmark SET sourceId = ? WHERE sourceId = ?",
parameters = 2,
binders = {
bindString(0, newFeedId)
bindString(1, oldFeedId)
}
)

driver.execute(
identifier = null,
sql = "UPDATE post SET sourceId = '$newFeedId' WHERE sourceId = '$oldFeedId'",
parameters = 0,
binders = null
sql = "UPDATE post SET sourceId = ? WHERE sourceId = ?",
parameters = 2,
binders = {
bindString(0, newFeedId)
bindString(1, oldFeedId)
}
)
}

private fun migratePostLinkIdsToUuid(driver: SqlDriver, oldPostId: String) {
val newPostId = nameBasedUuidOf(oldPostId).toString()
driver.execute(
identifier = null,
sql = "UPDATE bookmark SET id = '$newPostId' WHERE id = '$oldPostId'",
parameters = 0,
binders = null
sql = "UPDATE bookmark SET id = ? WHERE id = ?",
parameters = 2,
binders = {
bindString(0, newPostId)
bindString(1, oldPostId)
}
)

driver.execute(
identifier = null,
sql = "UPDATE post_search SET id = '$newPostId' WHERE id = '$oldPostId'",
parameters = 0,
binders = null
sql = "UPDATE post_search SET id = ? WHERE id = ?",
parameters = 2,
binders = {
bindString(0, newPostId)
bindString(1, oldPostId)
}
)

driver.execute(
identifier = null,
sql = "UPDATE post SET id = '$newPostId' WHERE id = '$oldPostId'",
parameters = 0,
binders = null
sql = "UPDATE post SET id = ? WHERE id = ?",
parameters = 2,
binders = {
bindString(0, newPostId)
bindString(1, oldPostId)
}
)
}
}
Expand Down

0 comments on commit 1896a96

Please sign in to comment.