Add room image content_hash column if missing
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
package com.android.trisolarisserver.config
|
||||||
|
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.boot.ApplicationArguments
|
||||||
|
import org.springframework.boot.ApplicationRunner
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class RoomImageSchemaFix(
|
||||||
|
private val jdbcTemplate: JdbcTemplate
|
||||||
|
) : ApplicationRunner {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(RoomImageSchemaFix::class.java)
|
||||||
|
|
||||||
|
override fun run(args: ApplicationArguments) {
|
||||||
|
val version = jdbcTemplate.queryForObject("select version()", String::class.java) ?: return
|
||||||
|
if (!version.contains("PostgreSQL", ignoreCase = true)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasContentHash = jdbcTemplate.queryForObject(
|
||||||
|
"""
|
||||||
|
select count(*)
|
||||||
|
from information_schema.columns
|
||||||
|
where table_name = 'room_image'
|
||||||
|
and column_name = 'content_hash'
|
||||||
|
""".trimIndent(),
|
||||||
|
Int::class.java
|
||||||
|
) ?: 0
|
||||||
|
|
||||||
|
if (hasContentHash == 0) {
|
||||||
|
logger.info("Adding room_image.content_hash column")
|
||||||
|
jdbcTemplate.execute("alter table room_image add column content_hash text")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,8 +33,8 @@ class RoomImage(
|
|||||||
@Column(name = "size_bytes", nullable = false)
|
@Column(name = "size_bytes", nullable = false)
|
||||||
var sizeBytes: Long,
|
var sizeBytes: Long,
|
||||||
|
|
||||||
@Column(name = "content_hash", nullable = false)
|
@Column(name = "content_hash")
|
||||||
var contentHash: String,
|
var contentHash: String? = null,
|
||||||
|
|
||||||
@Column(name = "room_type_code")
|
@Column(name = "room_type_code")
|
||||||
var roomTypeCode: String? = null,
|
var roomTypeCode: String? = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user