From d631b0e20aabcf1005064bf7754cb938a25bcbbe Mon Sep 17 00:00:00 2001 From: wowo-zZ Date: Sat, 14 Mar 2026 11:19:49 +0800 Subject: [PATCH] fix(ops): resolve storage permission and audit log JSONB type issues Fixes two critical issues when deploying with runtime.sh: 1. Storage Permission Error - Problem: AccessDeniedException when publishing skills - Root cause: /var/lib/skillhub/storage owned by root, but app runs as 'app' user - Solution: Pre-create storage directory with correct permissions in Dockerfile 2. Audit Log JSONB Type Error - Problem: PostgreSQL JSONB type mismatch when recording audit logs - Root cause: Missing type mapping annotation in AuditLog entity - Solution: Add @JdbcTypeCode(SqlTypes.JSON) annotation and V7 migration Changes: - server/Dockerfile: Add storage directory creation and permission setup - server/skillhub-domain/.../AuditLog.java: Add @JdbcTypeCode annotation - server/skillhub-app/.../V7__fix_audit_log_jsonb_type.sql: Migration for existing data Impact: - New deployments: Issues resolved automatically - Existing deployments: Flyway auto-applies V7 migration on upgrade --- server/Dockerfile | 5 ++++- .../db/migration/V7__fix_audit_log_jsonb_type.sql | 12 ++++++++++++ .../com/iflytek/skillhub/domain/audit/AuditLog.java | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql diff --git a/server/Dockerfile b/server/Dockerfile index dbac3589..a57eaaef 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -24,7 +24,10 @@ WORKDIR /app COPY --from=build /app/skillhub-app/target/*.jar app.jar -RUN chown -R app:app /app +# Create storage directory and set permissions +RUN mkdir -p /var/lib/skillhub/storage && \ + chown -R app:app /app /var/lib/skillhub/storage + USER app EXPOSE 8080 diff --git a/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql b/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql new file mode 100644 index 00000000..becd1661 --- /dev/null +++ b/server/skillhub-app/src/main/resources/db/migration/V7__fix_audit_log_jsonb_type.sql @@ -0,0 +1,12 @@ +-- Fix audit_log detail_json column to properly handle JSONB type +-- This migration ensures existing data is compatible with the JSONB type + +-- The column is already defined as jsonb in V1, but we need to ensure +-- any existing string data can be properly cast to jsonb +ALTER TABLE audit_log +ALTER COLUMN detail_json TYPE jsonb +USING CASE + WHEN detail_json IS NULL THEN NULL + WHEN detail_json = '' THEN NULL + ELSE detail_json::jsonb +END; diff --git a/server/skillhub-domain/src/main/java/com/iflytek/skillhub/domain/audit/AuditLog.java b/server/skillhub-domain/src/main/java/com/iflytek/skillhub/domain/audit/AuditLog.java index 61352599..2c7e9eea 100644 --- a/server/skillhub-domain/src/main/java/com/iflytek/skillhub/domain/audit/AuditLog.java +++ b/server/skillhub-domain/src/main/java/com/iflytek/skillhub/domain/audit/AuditLog.java @@ -7,6 +7,8 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.PrePersist; import jakarta.persistence.Table; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; import java.time.Instant; @Entity @@ -38,7 +40,8 @@ public class AuditLog { @Column(name = "user_agent", length = 512) private String userAgent; - @Column(name = "detail_json", columnDefinition = "jsonb") + @Column(name = "detail_json") + @JdbcTypeCode(SqlTypes.JSON) private String detailJson; @Column(name = "created_at", nullable = false, updatable = false)