Skip to content

Commit

Permalink
- migration
Browse files Browse the repository at this point in the history
Signed-off-by: samoylenkodmitry <[email protected]>
  • Loading branch information
samoylenkodmitry committed Jun 16, 2024
1 parent 54febdb commit ef8d9a9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/src/main/kotlin/in/shrtl/app/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,22 @@ fun initDB() {
SchemaUtils.create(Urls, Users)
// Check and add the clicks column if it doesn't exist
val clicksColumnExists =
exec("SELECT column_name FROM information_schema.columns WHERE table_name='urls' AND column_name='clicks'") { rs ->
rs.next()
}
exec(
"SELECT column_name FROM information_schema.columns WHERE table_name='urls' AND column_name='clicks'",
) { rs -> rs.next() }

if (clicksColumnExists == false) {
exec("ALTER TABLE urls ADD COLUMN clicks BIGINT")
exec("ALTER TABLE urls ADD COLUMN clicks BIGINT DEFAULT 0")
}

// Check and add the qr_clicks column if it doesn't exist
val qrClicksColumnExists =
exec("SELECT column_name FROM information_schema.columns WHERE table_name='urls' AND column_name='qr_clicks'") { rs ->
rs.next()
}
exec(
"SELECT column_name FROM information_schema.columns WHERE table_name='urls' AND column_name='qr_clicks'",
) { rs -> rs.next() }

if (qrClicksColumnExists == false) {
exec("ALTER TABLE urls ADD COLUMN qr_clicks BIGINT")
exec("ALTER TABLE urls ADD COLUMN qr_clicks BIGINT DEFAULT 0")
}
}
}
Expand Down

0 comments on commit ef8d9a9

Please sign in to comment.