mirror of
https://github.com/ChuckNorrison/LightningTipBot.git
synced 2026-08-18 13:08:52 +02:00
* anonymous user ID for lnurl * anonymous lnurl * migrate at every start, not good * anon id at user creation * migrations file * fix database migration task * remove comment * anon label Co-authored-by: lngohumble <lngohumble@gmail.com>
26 lines
636 B
Go
26 lines
636 B
Go
package database
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
|
|
"github.com/LightningTipBot/LightningTipBot/internal/str"
|
|
log "github.com/sirupsen/logrus"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func MigrateAnonIdHash(db *gorm.DB) error {
|
|
users := []lnbits.User{}
|
|
_ = db.Find(&users)
|
|
for _, u := range users {
|
|
log.Info(u.ID, str.Int32Hash(u.ID))
|
|
u.AnonID = fmt.Sprint(str.Int32Hash(u.ID))
|
|
tx := db.Save(u)
|
|
if tx.Error != nil {
|
|
errmsg := fmt.Sprintf("[MigrateAnonIdHash] Error: Couldn't migrate user %s (%d)", u.Telegram.Username, u.Telegram.ID)
|
|
log.Errorln(errmsg)
|
|
return tx.Error
|
|
}
|
|
}
|
|
return nil
|
|
}
|