Reject duplicate guest documents by hash
All checks were successful
build-and-deploy / build-deploy (push) Successful in 31s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 31s
This commit is contained in:
@@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user