-- V2__link_guardian_user.sql
-- Menghubungkan Guardian <-> User setelah DataSeeder Java insert kedua akun
-- Script ini dijalankan SETELAH aplikasi sudah seed data via DataSeeder.java
-- Jika DataSeeder yang handle relasi, migration ini bisa jadi no-op safety net

DO $$
DECLARE
    v_guardian_id BIGINT;
    v_user_id     BIGINT;
BEGIN
    SELECT id INTO v_guardian_id FROM users WHERE email = 'guardian@walkguide.com';
    SELECT id INTO v_user_id     FROM users WHERE email = 'user@walkguide.com';

    IF v_guardian_id IS NOT NULL AND v_user_id IS NOT NULL THEN
        UPDATE users SET connected_to = v_user_id     WHERE id = v_guardian_id;
        UPDATE users SET connected_to = v_guardian_id WHERE id = v_user_id;
    END IF;
END $$;
