Skip to content

Commit 89ee633

Browse files
committed
fix: migrate legacy peak-level sign-ups onto their peak's expedition
Existing sign-ups (event_id NULL, made before per-expedition joins) now get attached to the peak's earliest non-cancelled plan event on startup, so '+n going' shows inside the expedition. Idea peaks with no plan event stay peak-level.
1 parent cb3def3 commit 89ee633

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/store.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ fn run_migrations(conn: &Connection) {
160160
let _ = conn.execute("ALTER TABLE peaks ADD COLUMN is_challenge INTEGER NOT NULL DEFAULT 0", []);
161161
let _ = conn.execute("ALTER TABLE peaks ADD COLUMN expedition_group TEXT", []);
162162
let _ = conn.execute("ALTER TABLE peak_signups ADD COLUMN event_id TEXT", []);
163+
// Attach legacy peak-level sign-ups to their peak's (earliest) planned expedition,
164+
// so the "+n going" now shows inside the expedition. Idea peaks (no plan event)
165+
// keep event_id NULL and stay peak-level.
166+
let _ = conn.execute(
167+
"UPDATE peak_signups SET event_id = (
168+
SELECT ce.id FROM calendar_events ce
169+
WHERE LOWER(ce.peak_name) = peak_signups.peak_key
170+
AND ce.event_type = 'plan' AND ce.status != 'cancelled'
171+
ORDER BY ce.planned_date ASC LIMIT 1)
172+
WHERE event_id IS NULL
173+
AND EXISTS (SELECT 1 FROM calendar_events ce
174+
WHERE LOWER(ce.peak_name) = peak_signups.peak_key
175+
AND ce.event_type = 'plan' AND ce.status != 'cancelled')",
176+
[],
177+
);
163178
let _ = conn.execute("ALTER TABLE users ADD COLUMN avatar_url TEXT", []);
164179
let _ = conn.execute("ALTER TABLE calendar_events ADD COLUMN category TEXT NOT NULL DEFAULT 'peak'", []);
165180
let _ = conn.execute("ALTER TABLE calendar_events ADD COLUMN track TEXT", []);

0 commit comments

Comments
 (0)