cmd/ismdb: include campaign ids from race rewards

This commit is contained in:
2026-11-09 15:02:18 -05:00
parent 6ca27e79bf
commit a67353f0b6
3 changed files with 36 additions and 0 deletions
+17
View File
@@ -20,6 +20,9 @@ const appID int32 = 0x157db
//go:embed schema-00.sql
var schema0 string
//go:embed schema-01.sql
var schema1 string
//go:embed schema-final.sql
var schemaFinal string
@@ -27,6 +30,7 @@ func opendb(uri, journalMode string) *sqlitemigration.Pool {
schema := sqlitemigration.Schema{
Migrations: []string{
schema0,
schema1,
},
AppID: appID,
RepeatableMigration: schemaFinal,
@@ -275,10 +279,13 @@ func insertRaces(conn *sqlite.Conn, log *slog.Logger, races []ism.IdleSingleMode
log.Debug("insert races")
raceStmt := conn.Prep(`INSERT INTO race_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
rewardStmt := conn.Prep(`INSERT INTO race_reward VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
cmpgnStmt := conn.Prep(`INSERT INTO race_campaign VALUES (?, ?, ?, ?)`)
raceStmt.BindInt64(1, trainerID)
raceStmt.BindInt64(2, int64(trainedChara))
rewardStmt.BindInt64(1, trainerID)
rewardStmt.BindInt64(2, int64(trainedChara))
cmpgnStmt.BindInt64(1, trainerID)
cmpgnStmt.BindInt64(2, int64(trainedChara))
for _, r := range races {
raceStmt.BindInt64(3, int64(r.RaceHistory.Turn))
raceStmt.BindInt64(4, int64(r.RaceHistory.ProgramID))
@@ -344,6 +351,16 @@ func insertRaces(conn *sqlite.Conn, log *slog.Logger, races []ism.IdleSingleMode
return fmt.Errorf("inserting race reward: %w", err)
}
}
cmpgnStmt.BindInt64(3, int64(r.RaceHistory.Turn))
for _, c := range r.RaceRewardInfo.CampaignIDs {
cmpgnStmt.BindInt64(4, int64(c))
_, err := cmpgnStmt.Step()
err = errors.Join(err, cmpgnStmt.Reset())
if err != nil {
return fmt.Errorf("inserting race campaign: %w", err)
}
}
}
return nil
}