70 lines
2.3 KiB
Kotlin
70 lines
2.3 KiB
Kotlin
package com.android.trisolarisserver.config
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate
|
|
import org.springframework.stereotype.Component
|
|
|
|
@Component
|
|
class BookingSchemaFix(
|
|
private val jdbcTemplate: JdbcTemplate
|
|
) : PostgresSchemaFix(jdbcTemplate) {
|
|
|
|
override fun runPostgres(jdbcTemplate: JdbcTemplate) {
|
|
val hasExpectedGuestCount = jdbcTemplate.queryForObject(
|
|
"""
|
|
select count(*)
|
|
from information_schema.columns
|
|
where table_name = 'booking'
|
|
and column_name = 'expected_guest_count'
|
|
""".trimIndent(),
|
|
Int::class.java
|
|
) ?: 0
|
|
|
|
if (hasExpectedGuestCount == 0) {
|
|
logger.info("Adding booking.expected_guest_count column")
|
|
jdbcTemplate.execute("alter table booking add column expected_guest_count integer")
|
|
}
|
|
|
|
val hasFromCity = jdbcTemplate.queryForObject(
|
|
"""
|
|
select count(*)
|
|
from information_schema.columns
|
|
where table_name = 'booking'
|
|
and column_name = 'from_city'
|
|
""".trimIndent(),
|
|
Int::class.java
|
|
) ?: 0
|
|
if (hasFromCity == 0) {
|
|
logger.info("Adding booking.from_city column")
|
|
jdbcTemplate.execute("alter table booking add column from_city varchar")
|
|
}
|
|
|
|
val hasToCity = jdbcTemplate.queryForObject(
|
|
"""
|
|
select count(*)
|
|
from information_schema.columns
|
|
where table_name = 'booking'
|
|
and column_name = 'to_city'
|
|
""".trimIndent(),
|
|
Int::class.java
|
|
) ?: 0
|
|
if (hasToCity == 0) {
|
|
logger.info("Adding booking.to_city column")
|
|
jdbcTemplate.execute("alter table booking add column to_city varchar")
|
|
}
|
|
|
|
val hasMemberRelation = jdbcTemplate.queryForObject(
|
|
"""
|
|
select count(*)
|
|
from information_schema.columns
|
|
where table_name = 'booking'
|
|
and column_name = 'member_relation'
|
|
""".trimIndent(),
|
|
Int::class.java
|
|
) ?: 0
|
|
if (hasMemberRelation == 0) {
|
|
logger.info("Adding booking.member_relation column")
|
|
jdbcTemplate.execute("alter table booking add column member_relation varchar")
|
|
}
|
|
}
|
|
}
|