And my guess is if I have `/documents/:id` route to a SQLite DO that creates the schema in the const

And my guess is if I have
/documents/:id
route to a SQLite DO that creates the schema in the constructor, then if a hacker were to spam my service with a bunch of
GET /documents/XXXXX
calls trying to find a valid document, that every one of those invalid GETs would create a new DO that wouldn't be deleted because the SQLite database would be created simply by the act of accessing it, even if it returns a 404. Is that right?

With the old storage, accessing a DO without any data in it wouldn't cause a new DO to stick around. Unless data is actually stored in the storage, there is nothing that keeps it around after access.

Does anyone have strategies to preventing this behavior? Would the right way to do it be to create the database on first write (POST) and any GETs would check if the tables exist first and 404 if they don't. I suppose this create-db-on-write behavior would also solve the other issue above where I had to track if the DO was deleted. Thanks for letting me talk it out!

Is this a known best practice? Should the examples be updated to guide people to not create the database in the constructor since any access to a non-existent DO will create a new DB file that will stick around forever?
Was this page helpful?