Files
TrisolarisServer/src/main/kotlin/com/android/trisolarisserver/config/PayuPaymentLinkSettingsSchemaFix.kt
androidlover5842 e6df0b7bb2
All checks were successful
build-and-deploy / build-deploy (push) Successful in 36s
Allow null payment link access token
2026-01-30 08:22:07 +05:30

62 lines
2.3 KiB
Kotlin

package com.android.trisolarisserver.config
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.stereotype.Component
@Component
class PayuPaymentLinkSettingsSchemaFix(
private val jdbcTemplate: JdbcTemplate
) : PostgresSchemaFix(jdbcTemplate) {
override fun runPostgres(jdbcTemplate: JdbcTemplate) {
val hasTable = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.tables
where table_name = 'payu_payment_link_settings'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasTable == 0) {
logger.info("Creating payu_payment_link_settings table")
jdbcTemplate.execute(
"""
create table payu_payment_link_settings (
id uuid primary key,
property_id uuid not null unique references property(id) on delete cascade,
merchant_id text not null,
client_id text,
client_secret text,
access_token text,
token_expires_at timestamptz,
is_test boolean not null default false,
updated_at timestamptz not null
)
""".trimIndent()
)
}
ensureColumn("payu_payment_link_settings", "client_id", "text")
ensureColumn("payu_payment_link_settings", "client_secret", "text")
ensureColumn("payu_payment_link_settings", "access_token", "text")
ensureColumn("payu_payment_link_settings", "token_expires_at", "timestamptz")
jdbcTemplate.execute("alter table payu_payment_link_settings alter column access_token drop not null")
}
private fun ensureColumn(table: String, column: String, type: String) {
val exists = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.columns
where table_name = '$table'
and column_name = '$column'
""".trimIndent(),
Int::class.java
) ?: 0
if (exists == 0) {
logger.info("Adding $table.$column column")
jdbcTemplate.execute("alter table $table add column $column $type")
}
}
}