-- Relay server nodes registry
CREATE TABLE relay_nodes (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    name VARCHAR(64) NOT NULL,
    url TEXT NOT NULL UNIQUE,
    region VARCHAR(32) NOT NULL DEFAULT 'auto',
    is_active BOOLEAN NOT NULL DEFAULT TRUE,
    priority INTEGER NOT NULL DEFAULT 0,
    last_ping_ms INTEGER,                     -- measured RTT in ms
    last_checked_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Seed with official relay nodes
INSERT INTO relay_nodes (name, url, region, priority) VALUES 
    ('官方节点 - 主线路', 'funmc.com:7900', 'auto', 100),
    ('官方节点 - 备用线路', 'funmc.com:7901', 'auto', 50);
