chore: update
This commit is contained in:
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -161,11 +162,42 @@ func InitDB() *Database {
|
||||
log.Fatalf("❌ Erreur migration commandes.referral_used: %v", err)
|
||||
}
|
||||
|
||||
// Migration: points extra pour les pools de points supplémentaires (pool[2+])
|
||||
// Migration: points extra pour tous les pools de points (stockage dynamique par clé)
|
||||
if _, err = database.Exec(`ALTER TABLE clients ADD COLUMN IF NOT EXISTS points_extra JSONB NOT NULL DEFAULT '{}'::jsonb`); err != nil {
|
||||
log.Fatalf("❌ Erreur migration clients.points_extra: %v", err)
|
||||
}
|
||||
|
||||
// Migration: copier point/point_zipette → points_extra[pool.Key] selon les clés admin
|
||||
{
|
||||
var poolsJSON string
|
||||
_ = database.QueryRow(`SELECT value FROM app_settings WHERE key = 'points_pools'`).Scan(&poolsJSON)
|
||||
if poolsJSON != "" {
|
||||
var pools []struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
if jsonErr := json.Unmarshal([]byte(poolsJSON), &pools); jsonErr == nil {
|
||||
if len(pools) > 0 && pools[0].Key != "" {
|
||||
k0 := pools[0].Key
|
||||
if _, mErr := database.Exec(`UPDATE clients SET points_extra = points_extra || jsonb_build_object($1::text, point) WHERE point > 0 AND NOT (points_extra ? $1)`, k0); mErr != nil {
|
||||
log.Printf("⚠️ Migration points_extra pool[0] (%s): %v", k0, mErr)
|
||||
} else {
|
||||
log.Printf("✅ Migration points_extra pool[0] key=%s", k0)
|
||||
}
|
||||
}
|
||||
if len(pools) > 1 && pools[1].Key != "" {
|
||||
k1 := pools[1].Key
|
||||
if _, mErr := database.Exec(`UPDATE clients SET points_extra = points_extra || jsonb_build_object($1::text, point_zipette) WHERE point_zipette > 0 AND NOT (points_extra ? $1)`, k1); mErr != nil {
|
||||
log.Printf("⚠️ Migration points_extra pool[1] (%s): %v", k1, mErr)
|
||||
} else {
|
||||
log.Printf("✅ Migration points_extra pool[1] key=%s", k1)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Printf("ℹ️ Migration points_extra: aucun pool configuré (app_settings vide)")
|
||||
}
|
||||
}
|
||||
|
||||
// Lancer le nettoyage périodique des tokens expirés
|
||||
go database.cleanExpiredTokensPeriodically()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user