Make room images list public and fix tag schema
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s

This commit is contained in:
androidlover5842
2026-01-27 19:11:48 +05:30
parent 5b1564cdb3
commit 59094f80ba
4 changed files with 82 additions and 2 deletions

View File

@@ -0,0 +1,80 @@
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 RoomImageTagSchemaFix(
private val jdbcTemplate: JdbcTemplate
) : ApplicationRunner {
private val logger = LoggerFactory.getLogger(RoomImageTagSchemaFix::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 hasOldRoomImageId = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.columns
where table_name = 'room_image_tag'
and column_name = 'room_image_id'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasOldRoomImageId > 0) {
logger.info("Dropping legacy room_image_tag table")
jdbcTemplate.execute("drop table if exists room_image_tag cascade")
}
val hasRoomImageTag = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.tables
where table_name = 'room_image_tag'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasRoomImageTag == 0) {
logger.info("Creating room_image_tag table")
jdbcTemplate.execute(
"""
create table room_image_tag (
id uuid primary key,
name text not null unique,
created_at timestamptz not null
)
""".trimIndent()
)
}
val hasLink = jdbcTemplate.queryForObject(
"""
select count(*)
from information_schema.tables
where table_name = 'room_image_tag_link'
""".trimIndent(),
Int::class.java
) ?: 0
if (hasLink == 0) {
logger.info("Creating room_image_tag_link table")
jdbcTemplate.execute(
"""
create table room_image_tag_link (
room_image_id uuid not null,
tag_id uuid not null
)
""".trimIndent()
)
}
}
}