From 5fe19cf54c696738aa9526b4d6c4e1882e97dd2e Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Thu, 29 Jan 2026 12:05:40 +0530 Subject: [PATCH] Update room_stay rate_source constraint --- .../config/RoomStaySchemaFix.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/kotlin/com/android/trisolarisserver/config/RoomStaySchemaFix.kt diff --git a/src/main/kotlin/com/android/trisolarisserver/config/RoomStaySchemaFix.kt b/src/main/kotlin/com/android/trisolarisserver/config/RoomStaySchemaFix.kt new file mode 100644 index 0000000..82aab1b --- /dev/null +++ b/src/main/kotlin/com/android/trisolarisserver/config/RoomStaySchemaFix.kt @@ -0,0 +1,35 @@ +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() + ) + } +}