-- Ownership for portal JWT users (modules, peers, firewall).
ALTER TABLE module ADD COLUMN IF NOT EXISTS created_by_user_id TEXT;
ALTER TABLE bgp_peer ADD COLUMN IF NOT EXISTS created_by_user_id TEXT;
ALTER TABLE firewall_client ADD COLUMN IF NOT EXISTS created_by_user_id TEXT;
ALTER TABLE firewall_rule ADD COLUMN IF NOT EXISTS created_by_user_id TEXT;

CREATE INDEX IF NOT EXISTS idx_module_created_by ON module (tenant_id, created_by_user_id);
CREATE INDEX IF NOT EXISTS idx_bgp_peer_created_by ON bgp_peer (tenant_id, created_by_user_id);
CREATE INDEX IF NOT EXISTS idx_firewall_client_created_by ON firewall_client (tenant_id, created_by_user_id);
CREATE INDEX IF NOT EXISTS idx_firewall_rule_created_by ON firewall_rule (tenant_id, created_by_user_id);
