Files
TrisolarisServer/src/main/kotlin/com/android/trisolarisserver/config/IssuedCardSchemaFix.kt
androidlover5842 9b64b34ab9
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
Deduplicate logic across controllers, auth, and schema fixes
2026-01-28 23:03:48 +05:30

45 lines
1.5 KiB
Kotlin

package com.android.trisolarisserver.config
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.stereotype.Component
@Component
class IssuedCardSchemaFix(
private val jdbcTemplate: JdbcTemplate
) : PostgresSchemaFix(jdbcTemplate) {
override fun runPostgres(jdbcTemplate: JdbcTemplate) {
val isNullable = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.columns
where table_name = 'issued_card'
and column_name = 'room_stay_id'
and is_nullable = 'YES'
""".trimIndent(),
Int::class.java
) ?: 0
if (isNullable == 0) {
logger.info("Dropping NOT NULL on issued_card.room_stay_id")
jdbcTemplate.execute("alter table issued_card alter column room_stay_id drop not null")
}
val uniqueIndexExists = jdbcTemplate.queryForObject(
"""
select count(*)
from pg_indexes
where schemaname = 'public'
and tablename = 'issued_card'
and indexname = 'idx_issued_card_property_card_id_unique'
""".trimIndent(),
Int::class.java
) ?: 0
if (uniqueIndexExists > 0) {
logger.info("Dropping unique index on issued_card(property_id, lower(card_id))")
jdbcTemplate.execute("drop index if exists idx_issued_card_property_card_id_unique")
}
}
}