Add database functions and upgrade queries for uptime logging feature