Periodically re-importing D1 database and Maintenance mode

I have a read-only REST API serving (semi) static data. Each month the data changes and we basically get a full name database; there is no diff or whatsoever available. So my idea was to drop the existing D1 tables, and run the import script. And in the meantime return a maintenance response. Could I use a Environment variable MAINTENACE_MODE for this, and when flipping will Cloudflare workers pick it up directly? Or is there a better way to implement this scenario?
2 Replies
Hello, I’m Allie!
What if you have two DBs? When you want to update, write to the one that isn’t currently in use. Then, once it’s complete, you rebind your Worker to that DB
Marcel Overdijk
Marcel OverdijkOP2d ago
Yes that sounds as good approach as well, thx! Now I'm also caching data in KV namespace, is there an easy way to purge the whole namespace? I would like to avoind having to clear all keys one by one...? Or should I create a new KV namespace and bind that to the worker (and delete the old one)? If I rebind the D1 and KV namespace it takes immediate effect?

Did you find this page helpful?