36 lines
1.1 KiB
Kotlin
36 lines
1.1 KiB
Kotlin
package com.android.trisolarisserver.config
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate
|
|
import org.springframework.stereotype.Component
|
|
|
|
@Component
|
|
class RoomStaySchemaFix(
|
|
private val jdbcTemplate: JdbcTemplate
|
|
) : PostgresSchemaFix(jdbcTemplate) {
|
|
|
|
override fun runPostgres(jdbcTemplate: JdbcTemplate) {
|
|
val exists = jdbcTemplate.queryForObject(
|
|
"""
|
|
select count(*)
|
|
from information_schema.table_constraints
|
|
where table_name = 'room_stay'
|
|
and constraint_name = 'room_stay_rate_source_check'
|
|
""".trimIndent(),
|
|
Int::class.java
|
|
) ?: 0
|
|
|
|
if (exists > 0) {
|
|
logger.info("Updating room_stay_rate_source_check constraint")
|
|
jdbcTemplate.execute("alter table room_stay drop constraint room_stay_rate_source_check")
|
|
}
|
|
|
|
jdbcTemplate.execute(
|
|
"""
|
|
alter table room_stay
|
|
add constraint room_stay_rate_source_check
|
|
check (rate_source in ('MANUAL','PRESET','RATE_PLAN','NEGOTIATED','OTA'))
|
|
""".trimIndent()
|
|
)
|
|
}
|
|
}
|