D1 Best Practices dev/prod modes and --local and --remote flags

Hi! What are best practices around databases with D1 for building web apps that have dev and prod modes? I tried creating a wrangler.toml like this:
#:schema node_modules/wrangler/config-schema.json
name = "server"
main = "src/index.ts"
compatibility_date = "2024-06-14"

[env.dev]
d1_databases = [
{ binding = "DB", database_name = "d1", database_id = "8574d62f-02ae-4843-a25a-3700a2b5ebc1" }
]

[env.prod]
d1_databases = [
{ binding = "DB", database_name = "d1", database_id = "8574d62f-02ae-4843-a25a-3700a2b5ebc1" }
]
#:schema node_modules/wrangler/config-schema.json
name = "server"
main = "src/index.ts"
compatibility_date = "2024-06-14"

[env.dev]
d1_databases = [
{ binding = "DB", database_name = "d1", database_id = "8574d62f-02ae-4843-a25a-3700a2b5ebc1" }
]

[env.prod]
d1_databases = [
{ binding = "DB", database_name = "d1", database_id = "8574d62f-02ae-4843-a25a-3700a2b5ebc1" }
]
notice the ids are the same. when I create migrations, I have to use --env=dev and --env=prod flags. But not I have duplicated migrations in the same folder. What's the right way to do this? Should I have two databases in each env? A dev and a prod? Or should I control using the --local and --remote flags somehow?
1 Reply
Web Bae
Web BaeOP7mo ago
just found this, which looks to be using 2 separate databases. https://developers.cloudflare.com/d1/configuration/environments/ what is the difference between managing it like this vs. using --local and --dev flags?
Cloudflare Docs
Environments · Cloudflare D1 docs
Environments are different contexts that your code runs in. Cloudflare Developer Platform allows you to create and manage different environments. …
Want results from more Discord servers?
Add your server