Skip to content

Commit

Permalink
fix: use JDBC update statements for database migration
Browse files Browse the repository at this point in the history
avoid issues with special characters
  • Loading branch information
gotson committed Mar 17, 2020
1 parent 25a6613 commit f68e035
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ class V20200306175848__create_book_metadata_from_book : BaseJavaMigration() {
val now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss"))
books.forEach { book ->
val metadataId = jdbcTemplate.queryForObject("SELECT NEXTVAL('hibernate_sequence')", Int::class.java)
jdbcTemplate.execute("INSERT INTO book_metadata (ID, CREATED_DATE, LAST_MODIFIED_DATE, TITLE, NUMBER, NUMBER_SORT) VALUES ($metadataId, '$now', '$now', '${book["name"]}', '${book["number"]}', '${book["number"]}')")
jdbcTemplate.execute("UPDATE book SET metadata_id = $metadataId WHERE id = ${book["id"]}")
jdbcTemplate.update(
"INSERT INTO book_metadata (ID, CREATED_DATE, LAST_MODIFIED_DATE, TITLE, NUMBER, NUMBER_SORT) VALUES (?, ?, ?, ?, ?, ?)",
metadataId,
now,
now,
book["name"],
book["number"],
book["number"]
)
jdbcTemplate.update(
"UPDATE book SET metadata_id = ? WHERE id = ?",
metadataId,
book["id"]
)
}

jdbcTemplate.execute("alter table book alter column metadata_id set not null")
Expand Down

0 comments on commit f68e035

Please sign in to comment.