Bindings depending on the environment

I have some bindings in my wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "my-database"
[[d1_databases]]
binding = "DB"
database_name = "my-database"
I would like to specify a different database for the preview env (when deploying on a different branch than main) BUT to keep the same binding. Ideally it would look like these:
[env.preview]
[[env.preview.d1_databases]]
binding = "DB"
database_name = "my-preview-database"
[env.preview]
[[env.preview.d1_databases]]
binding = "DB"
database_name = "my-preview-database"
I have digged in the doc and tried various things. This seems not possible. Of course you can have different binding name but then you have to change your code so it's of no help. Thx in advance for sharing your experience on this.
1 Reply
i40west
i40west2mo ago
This should work just how you have it, [[env.preview.d1_databases]]. Checking my own code, I have the database_id field in both binding sections as well as database_name, so maybe that is necessary? I do use the same binding name for both environments, with a different name and id, and it works as expected.
Want results from more Discord servers?
Add your server