23 lines
999 B
Go
23 lines
999 B
Go
package asset
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"kra/internal/data/ledger"
|
|
"kra/pkg/database/migration"
|
|
)
|
|
|
|
func Migrations() []migration.Step {
|
|
return []migration.Step{{ID: "202609190004_asset_schema", Migrate: func(db *gorm.DB) error {
|
|
return migration.CreateMissingTables(db, &ledger.WalletPO{}, &ledger.BalanceAdjustmentPO{})
|
|
}}, {ID: "202609220003_live_wallet_backfill", Migrate: func(db *gorm.DB) error {
|
|
// Historical client accounts predate live_wallets. Backfill only missing
|
|
// rows with the same 100-diamond welcome balance as a new registration;
|
|
// existing balances and administrative adjustments remain untouched.
|
|
return db.Exec(`INSERT INTO live_wallets (user_id, diamond_balance, total_recharge_cents, total_spent_diamonds, created_at, updated_at)
|
|
SELECT u.id, 100, 0, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
|
|
FROM sys_users u
|
|
WHERE u.deleted_at IS NULL AND u.authority_id = ?
|
|
AND NOT EXISTS (SELECT 1 FROM live_wallets w WHERE w.user_id = u.id)`, 1000).Error
|
|
}}}
|
|
}
|