Skip to content

Commit 93d88c7

Browse files
graylikemeclaude
andcommitted
fix: default standard gyro/cockpit/myomer when MegaMek omits them
MegaMek doesn't store gyro_type/cockpit_type/myomer_type when they are standard, leaving 3509 of 4225 mech rows with NULL FKs. Default to standard component type in scraper and backfill existing rows via migration. All three now at 100% match rate. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4e106b5 commit 93d88c7

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

crates/scraper/src/db.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,19 @@ pub async fn upsert_mech_data(
303303
let heatsink_type_id = if let Some(ref ht) = data.heat_sink_type {
304304
resolve_alias(pool, "heatsink_type_aliases", "heatsink_type_id", ht).await
305305
} else { None };
306-
let gyro_type_id = if let Some(ref gt) = data.gyro_type {
306+
// Default to standard gyro/cockpit/myomer when MegaMek omits the field
307+
let gyro_type_id = {
308+
let gt = data.gyro_type.as_deref().unwrap_or("Standard Gyro");
307309
resolve_alias(pool, "gyro_type_aliases", "gyro_type_id", gt).await
308-
} else { None };
309-
let cockpit_type_id = if let Some(ref ct) = data.cockpit_type {
310+
};
311+
let cockpit_type_id = {
312+
let ct = data.cockpit_type.as_deref().unwrap_or("Standard Cockpit");
310313
resolve_alias(pool, "cockpit_type_aliases", "cockpit_type_id", ct).await
311-
} else { None };
312-
let myomer_type_id = if let Some(ref mt) = data.myomer_type {
314+
};
315+
let myomer_type_id = {
316+
let mt = data.myomer_type.as_deref().unwrap_or("Standard");
313317
resolve_alias(pool, "myomer_type_aliases", "myomer_type_id", mt).await
314-
} else { None };
318+
};
315319

316320
sqlx::query(
317321
r#"INSERT INTO unit_mech_data (
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Backfill standard gyro/cockpit/myomer FKs where MegaMek omitted the field.
2+
-- MegaMek doesn't store gyro_type/cockpit_type/myomer_type when they are standard,
3+
-- leaving them NULL. Default these to the standard component type.
4+
5+
UPDATE unit_mech_data SET gyro_type_id = (
6+
SELECT gyro_type_id FROM gyro_type_aliases WHERE alias = 'Standard Gyro'
7+
) WHERE gyro_type_id IS NULL;
8+
9+
UPDATE unit_mech_data SET cockpit_type_id = (
10+
SELECT cockpit_type_id FROM cockpit_type_aliases WHERE alias = 'Standard Cockpit'
11+
) WHERE cockpit_type_id IS NULL;
12+
13+
UPDATE unit_mech_data SET myomer_type_id = (
14+
SELECT myomer_type_id FROM myomer_type_aliases WHERE alias = 'Standard'
15+
) WHERE myomer_type_id IS NULL;

seed/data.sql.gz

1.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)