Compare commits

...

2 Commits

Author SHA1 Message Date
zhouyonggao 18841ea58a fix(api): 移除对只读数据库的ALTER TABLE操作
由于数据库是只读的,移除ExportsAPI中尝试修改表结构的ensureOwnerColumn方法调用
同时从Dockerfile中移除APP_ENV=prod的环境变量设置
2025-11-28 17:32:22 +08:00
zhouyonggao 1fbc81f88c chore: 更新服务器日志文件 2025-11-28 17:11:44 +08:00
4 changed files with 105 additions and 15 deletions

View File

@ -13,6 +13,5 @@ COPY --from=build /app/web /app/web
COPY --from=build /app/server/config.test.yaml /app/server/config.test.yaml COPY --from=build /app/server/config.test.yaml /app/server/config.test.yaml
COPY --from=build /app/server/config.prod.yaml /app/server/config.prod.yaml COPY --from=build /app/server/config.prod.yaml /app/server/config.prod.yaml
RUN mkdir -p /app/storage/export RUN mkdir -p /app/storage/export
ENV APP_ENV=prod
EXPOSE 8077 EXPOSE 8077
ENTRYPOINT ["/app/bin/marketing-data-server"] ENTRYPOINT ["/app/bin/marketing-data-server"]

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,6 @@ import (
"marketing-system-data-tool/server/internal/api" "marketing-system-data-tool/server/internal/api"
"marketing-system-data-tool/server/internal/config" "marketing-system-data-tool/server/internal/config"
"marketing-system-data-tool/server/internal/db" "marketing-system-data-tool/server/internal/db"
"marketing-system-data-tool/server/internal/migrate"
"marketing-system-data-tool/server/internal/logging" "marketing-system-data-tool/server/internal/logging"
"net/http" "net/http"
"time" "time"
@ -14,6 +13,7 @@ import (
func main() { func main() {
cfg := config.Load() cfg := config.Load()
log.Println("APP_ENV:", os.Getenv("APP_ENV"))
if cfg.YMTKeyDecryptKeyB64 != "" { os.Setenv("YMT_KEY_DECRYPT_KEY_B64", cfg.YMTKeyDecryptKeyB64) } if cfg.YMTKeyDecryptKeyB64 != "" { os.Setenv("YMT_KEY_DECRYPT_KEY_B64", cfg.YMTKeyDecryptKeyB64) }
_ = logging.Init("log") _ = logging.Init("log")
log.Println("connecting YMT MySQL:", cfg.YMTDB.Host+":"+cfg.YMTDB.Port, "db", cfg.YMTDB.Name, "user", cfg.YMTDB.User) log.Println("connecting YMT MySQL:", cfg.YMTDB.Host+":"+cfg.YMTDB.Port, "db", cfg.YMTDB.Name, "user", cfg.YMTDB.User)
@ -32,13 +32,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
if cfg.YMTDB.DSN() != "" { _ = ymt
if err := migrate.Apply(ymt); err != nil {
log.Fatal(err)
}
} else {
log.Println("skip migrations: YMT DSN missing")
}
r := api.NewRouter(ymt, marketing) r := api.NewRouter(ymt, marketing)
addr := ":" + func() string { addr := ":" + func() string {
s := cfg.Port s := cfg.Port

View File

@ -61,10 +61,8 @@ func ExportsHandler(meta, marketing *sql.DB) http.Handler {
}) })
} }
func (a *ExportsAPI) ensureOwnerColumn() { // owner_id 列在只读库不做运行时变更,避免 ALTER TABLE 触发错误
// Try to add owner_id column if not exists; ignore errors func (a *ExportsAPI) ensureOwnerColumn() {}
_, _ = a.meta.Exec("ALTER TABLE export_jobs ADD COLUMN owner_id BIGINT UNSIGNED NOT NULL DEFAULT 0")
}
type ExportPayload struct { type ExportPayload struct {
TemplateID uint64 `json:"template_id"` TemplateID uint64 `json:"template_id"`
@ -947,7 +945,6 @@ func toString(v interface{}) string {
} }
} }
func (a *ExportsAPI) list(w http.ResponseWriter, r *http.Request) { func (a *ExportsAPI) list(w http.ResponseWriter, r *http.Request) {
a.ensureOwnerColumn()
q := r.URL.Query() q := r.URL.Query()
page := 1 page := 1
size := 15 size := 15