Reject duplicate guest documents by hash
All checks were successful
build-and-deploy / build-deploy (push) Successful in 31s

This commit is contained in:
androidlover5842
2026-01-31 00:19:58 +05:30
parent bb2c40ed71
commit 0c32ff4102
4 changed files with 85 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
package com.android.trisolarisserver.config
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.stereotype.Component
@Component
class GuestDocumentSchemaFix(
private val jdbcTemplate: JdbcTemplate
) : PostgresSchemaFix(jdbcTemplate) {
override fun runPostgres(jdbcTemplate: JdbcTemplate) {
val hasTable = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.tables
where table_name = 'guest_document'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasTable == 0) return
val hasHash = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.columns
where table_name = 'guest_document'
and column_name = 'file_hash'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasHash == 0) {
logger.info("Adding file_hash to guest_document table")
jdbcTemplate.execute(
"""
alter table guest_document
add column file_hash varchar
""".trimIndent()
)
}
}
}