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 //go:embed schema-00.sql
var schema0 string var schema0 string
//go:embed schema-01.sql
var schema1 string
//go:embed schema-final.sql //go:embed schema-final.sql
var schemaFinal string var schemaFinal string
@@ -27,6 +30,7 @@ func opendb(uri, journalMode string) *sqlitemigration.Pool {
schema := sqlitemigration.Schema{ schema := sqlitemigration.Schema{
Migrations: []string{ Migrations: []string{
schema0, schema0,
schema1,
}, },
AppID: appID, AppID: appID,
RepeatableMigration: schemaFinal, RepeatableMigration: schemaFinal,
@@ -275,10 +279,13 @@ func insertRaces(conn *sqlite.Conn, log *slog.Logger, races []ism.IdleSingleMode
log.Debug("insert races") log.Debug("insert races")
raceStmt := conn.Prep(`INSERT INTO race_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) raceStmt := conn.Prep(`INSERT INTO race_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
rewardStmt := conn.Prep(`INSERT INTO race_reward VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`) rewardStmt := conn.Prep(`INSERT INTO race_reward VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`)
cmpgnStmt := conn.Prep(`INSERT INTO race_campaign VALUES (?, ?, ?, ?)`)
raceStmt.BindInt64(1, trainerID) raceStmt.BindInt64(1, trainerID)
raceStmt.BindInt64(2, int64(trainedChara)) raceStmt.BindInt64(2, int64(trainedChara))
rewardStmt.BindInt64(1, trainerID) rewardStmt.BindInt64(1, trainerID)
rewardStmt.BindInt64(2, int64(trainedChara)) rewardStmt.BindInt64(2, int64(trainedChara))
cmpgnStmt.BindInt64(1, trainerID)
cmpgnStmt.BindInt64(2, int64(trainedChara))
for _, r := range races { for _, r := range races {
raceStmt.BindInt64(3, int64(r.RaceHistory.Turn)) raceStmt.BindInt64(3, int64(r.RaceHistory.Turn))
raceStmt.BindInt64(4, int64(r.RaceHistory.ProgramID)) 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) 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 return nil
} }
+10
View File
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS race_campaign (
trainer_id INTEGER NOT NULL DEFAULT 0,
trained_chara_id INTEGER NOT NULL,
turn INTEGER NOT NULL,
campaign INTEGER NOT NULL,
PRIMARY KEY (trainer_id, trained_chara_id, turn, campaign),
FOREIGN KEY (trainer_id, trained_chara_id, turn) REFERENCES race_history ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS race_campaign_by_campaign ON race_campaign (campaign);
+9
View File
@@ -1,6 +1,7 @@
DROP VIEW IF EXISTS gain_event; DROP VIEW IF EXISTS gain_event;
DROP VIEW IF EXISTS gain_inspiration; DROP VIEW IF EXISTS gain_inspiration;
DROP VIEW IF EXISTS gain_support_card; DROP VIEW IF EXISTS gain_support_card;
DROP VIEW IF EXISTS career_chara_count;
CREATE VIEW gain_event AS CREATE VIEW gain_event AS
SELECT SELECT
@@ -86,3 +87,11 @@ SELECT
gain_end_closer gain_end_closer
FROM gain FROM gain
WHERE source > 1; WHERE source > 1;
CREATE VIEW career_chara_count AS
SELECT
trainer_id,
card_id,
COUNT(*)
FROM career
GROUP BY trainer_id, card_id;