Update mengyastore
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// migrate imports existing JSON data files into the MySQL database.
|
||||
// Run once after switching to DB storage:
|
||||
// migrate 将历史上导出的 JSON 数据文件导入 MySQL。
|
||||
// 在切到数据库存储方式后执行一次即可:
|
||||
//
|
||||
// go run ./cmd/migrate/main.go
|
||||
package main
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load from env / .env (run from repo root: go run ./cmd/migrate, or set ENV_FILE).
|
||||
// 从环境变量 / .env.development 加载(在仓库根目录执行 go run ./cmd/migrate,或设置 ENV_FILE)。
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("load config: %v", err)
|
||||
@@ -34,7 +34,7 @@ func main() {
|
||||
log.Fatalf("open db: %v", err)
|
||||
}
|
||||
|
||||
// Ensure tables exist
|
||||
// 确保表结构存在
|
||||
if err := db.AutoMigrate(
|
||||
&database.ProductRow{},
|
||||
&database.ProductCodeRow{},
|
||||
@@ -55,7 +55,7 @@ func main() {
|
||||
log.Println("✅ 数据导入完成!")
|
||||
}
|
||||
|
||||
// ─── Products ─────────────────────────────────────────────────────────────────
|
||||
// ─── 商品 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
type jsonProduct struct {
|
||||
ID string `json:"id"`
|
||||
@@ -123,7 +123,7 @@ func migrateProducts(db *gorm.DB) {
|
||||
log.Printf("[products] 导入 %s 失败: %v", p.ID, result.Error)
|
||||
continue
|
||||
}
|
||||
// Codes → product_codes
|
||||
// 卡密写入 product_codes 表
|
||||
for _, code := range p.Codes {
|
||||
if code == "" {
|
||||
continue
|
||||
@@ -137,7 +137,7 @@ func migrateProducts(db *gorm.DB) {
|
||||
log.Printf("[products] 导入 %d 条商品", len(products))
|
||||
}
|
||||
|
||||
// ─── Orders ───────────────────────────────────────────────────────────────────
|
||||
// ─── 订单 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
type jsonOrder struct {
|
||||
ID string `json:"id"`
|
||||
@@ -201,7 +201,7 @@ func migrateOrders(db *gorm.DB) {
|
||||
log.Printf("[orders] 导入 %d 条订单", len(orders))
|
||||
}
|
||||
|
||||
// ─── Wishlists ────────────────────────────────────────────────────────────────
|
||||
// ─── 收藏夹 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func migrateWishlists(db *gorm.DB) {
|
||||
data, err := os.ReadFile("data/json/wishlists.json")
|
||||
@@ -227,7 +227,7 @@ func migrateWishlists(db *gorm.DB) {
|
||||
log.Printf("[wishlists] 导入 %d 条收藏记录", count)
|
||||
}
|
||||
|
||||
// ─── Chats ────────────────────────────────────────────────────────────────────
|
||||
// ─── 聊天 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
type jsonChatMsg struct {
|
||||
ID string `json:"id"`
|
||||
@@ -269,7 +269,7 @@ func migrateChats(db *gorm.DB) {
|
||||
log.Printf("[chats] 导入 %d 条聊天消息", count)
|
||||
}
|
||||
|
||||
// ─── Site settings ────────────────────────────────────────────────────────────
|
||||
// ─── 站点设置 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
type jsonSite struct {
|
||||
TotalVisits int `json:"totalVisits"`
|
||||
|
||||
Reference in New Issue
Block a user