Definitely you can do this, the script I’ve shared is help you to build foundation. You can apply your logic and make it run as you expect.
Tip: first find out latest record in database, then find same in sheet and start grabbing from next row and insert into database.