- migration 000017: suffix_dirs tree (info-price style, two-root sidebar),
suffix_groups, suffixes, per-directory columns with value flag, cells,
row anchors and template files (stored under PACKAGE_STORAGE_ROOT)
- Go API /api/v1/suffix-admin/*: tree/page/CRUD/reorder for dirs, groups,
suffixes and columns; cell upsert; anchor toggle; template upload with
sha256 verification, scoped download/delete; admin session required
- RequiredSchemaVersion 16 -> 17
- Vue panel /suffixes (menu below payment plans): two roots (basic setup +
info-price directory tree), grouped suffix sheet with template upload,
add-column dialog with 值设置 checkbox (value cells store {anchor,value});
removed attribute-table/field-mapping/column-sort/value-setting toolbar
- tests: integration test (MYSQL_TEST_DSN gated) + 3 vitest cases
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const RequiredSchemaVersion = 17
|
|
|
|
func RegisterReadiness(r *gin.Engine, db *sql.DB) {
|
|
r.GET("/api/v1/health/ready", func(c *gin.Context) {
|
|
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Second)
|
|
defer cancel()
|
|
if err := CheckSchema(ctx, db); err != nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{"status": "not_ready"})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"status": "ready"})
|
|
})
|
|
}
|
|
|
|
func CheckSchema(ctx context.Context, db *sql.DB) error {
|
|
if db == nil {
|
|
return sql.ErrConnDone
|
|
}
|
|
var version uint64
|
|
var dirty bool
|
|
rows, err := db.QueryContext(ctx, "SELECT version, dirty FROM schema_migrations")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
if !rows.Next() {
|
|
return sql.ErrNoRows
|
|
}
|
|
if err := rows.Scan(&version, &dirty); err != nil {
|
|
return err
|
|
}
|
|
if rows.Next() || rows.Err() != nil || version != RequiredSchemaVersion || dirty {
|
|
return sql.ErrNoRows
|
|
}
|
|
return nil
|
|
}
|