feat: migrate to PostgreSQL GORM and MinIO file storage

Use UUID models and soft deletion, persist file relationships with deduplicated monthly MinIO objects, and add admin file management. Update mini-program media handling and add local dev configuration.
This commit is contained in:
2026-11-01 11:48:45 +08:00
parent 0530523750
commit 4934a69581
94 changed files with 4686 additions and 2147 deletions
+4 -4
View File
@@ -64,7 +64,7 @@ func Run(db *store.DB, wx *wechat.Client, interval time.Duration) {
}
type Sender interface {
SendSubscribeMessage(toUserID int64, templateType string, data map[string]string, page string, activityID int64, userID int64) bool
SendSubscribeMessage(toUserID string, templateType string, data map[string]string, page string, activityID string, userID string) bool
}
// force 只放宽时间和次数限制,仍检查成功记录、关系和分享权限。
@@ -96,16 +96,16 @@ func Once(db *store.DB, wx Sender, force bool) {
}
processed, success, fail, skip := 0, 0, 0, 0
for _, a := range activities {
activityID, userID, actionType := a.Int("id"), a.Int("user_id"), a.Str("action_type")
activityID, userID, actionType := a.Str("id"), a.Str("user_id"), a.Str("action_type")
nickname := a.Str("nickname")
if nickname == "" {
nickname = "你的TA"
}
partnerID := a.Int("to_user_id")
partnerID := a.Str("to_user_id")
// 扫描后共享开关或关系可能改变;实际发送前再次检查。
allowed, err := db.QueryOne(`SELECT u.period_visible FROM users u JOIN couples cp ON cp.id=u.couple_id AND cp.status='active'
JOIN users recipient ON recipient.id=? AND recipient.couple_id=cp.id
WHERE u.id=? AND cp.id=? AND u.id IN (cp.user1_id,cp.user2_id) AND recipient.id IN (cp.user1_id,cp.user2_id) AND recipient.id<>u.id`, partnerID, userID, a.Int("couple_id"))
WHERE u.id=? AND cp.id=? AND u.id IN (cp.user1_id,cp.user2_id) AND recipient.id IN (cp.user1_id,cp.user2_id) AND recipient.id<>u.id`, partnerID, userID, a.Str("couple_id"))
if err != nil || allowed == nil || ((actionType == "period_add" || actionType == "period_sex_add") && allowed.Int("period_visible") == 0) {
skip++
continue
+5 -5
View File
@@ -10,10 +10,10 @@ import (
type testSender struct {
calls int
to, from int64
to, from string
}
func (s *testSender) SendSubscribeMessage(to int64, typ string, data map[string]string, page string, activity, from int64) bool {
func (s *testSender) SendSubscribeMessage(to string, typ string, data map[string]string, page string, activity, from string) bool {
s.calls++
s.to, s.from = to, from
return true
@@ -56,12 +56,12 @@ func TestRetrySelectionAndPermissionRecheck(t *testing.T) {
}
db, _ := testdb.Open(t, steps)
sender := &testSender{}
Once(&store.DB{DB: db}, sender, tt.force)
Once(store.WrapSQL(db), sender, tt.force)
if sender.calls != tt.want {
t.Fatalf("sent %d want %d", sender.calls, tt.want)
}
if sender.calls > 0 && (sender.to != 2 || sender.from != 1) {
t.Fatalf("message must go to partner: from=%d to=%d", sender.from, sender.to)
if sender.calls > 0 && (sender.to != "2" || sender.from != "1") {
t.Fatalf("message must go to partner: from=%s to=%s", sender.from, sender.to)
}
})
}