3 ms·
>Should I create one database per user, for example? You can't. D1 won't let you create databases at runtime. At least that was the case last time I tried it,
by fauigerzigerk 3y ago
>Should I create one database per user, for example?
You can't. D1 won't let you create databases at runtime. At least that was the case last time I tried it, and it's what killed it for me.
- ibejoeb 3y agoNot really sure how you distinguish between runtime and something else. It seems to me that you could provision a "shard" as simply as executing in a worker: wrangler d1 create customer28 --experimental-backend wrangler d1 execute customer28 --file=schema.sql
- fauigerzigerk 3y agoWhat I mean is that workers cannot create databases. You have to create each database using wrangler (or the UI) and then edit the configuration file to add a binding. The binding becomes a variable in the JavaScript environment, which means you have to change the source code every time a new database is created. Therefore, creating a database per user as part of the user signup flow is not possible.
- ibejoeb 3y agoAh, I see. I thought it would be possible to dynamically set a secret which would effectively be a database uri. But upon further investigation, it does indeed need a redeploy. I suppose you could make something to write the bindings to the toml and trigger a redeploy, but that's definitely not pretty.