Auto restore state on startup from database