Auto-add room_type is_active column
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.android.trisolarisserver.config
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.boot.ApplicationArguments
|
||||
import org.springframework.boot.ApplicationRunner
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class RoomTypeSchemaFix(
|
||||
private val jdbcTemplate: JdbcTemplate
|
||||
) : ApplicationRunner {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(RoomTypeSchemaFix::class.java)
|
||||
|
||||
override fun run(args: ApplicationArguments) {
|
||||
val version = jdbcTemplate.queryForObject("select version()", String::class.java) ?: return
|
||||
if (!version.contains("PostgreSQL", ignoreCase = true)) {
|
||||
return
|
||||
}
|
||||
|
||||
val hasActive = jdbcTemplate.queryForObject(
|
||||
"""
|
||||
select count(*)
|
||||
from information_schema.columns
|
||||
where table_name = 'room_type'
|
||||
and column_name = 'is_active'
|
||||
""".trimIndent(),
|
||||
Int::class.java
|
||||
) ?: 0
|
||||
|
||||
if (hasActive == 0) {
|
||||
logger.info("Adding room_type.is_active column")
|
||||
jdbcTemplate.execute("alter table room_type add column is_active boolean not null default true")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user