From 6640757baa5b9de0ae3418439c10e39c9ad3c438 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 12:10:30 +0000 Subject: [PATCH 1/7] Adding information on how wrangler.toml is structured behind the scenes. --- .../docs/d1/configuration/environments.mdx | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index f92ba99262f1e79..21b047c925cd38f 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -25,3 +25,78 @@ d1_databases = [ ``` In the code above, the `staging` environment is using a different database (`DATABASE_NAME_1`) than the `production` environment (`DATABASE_NAME_2`). + +## Anatomy of `wrangler.toml` file + +If you have multiple environments in your D1 binding, your `wrangler.toml` may look like the following: + +```toml +[[env.abc]] + binding = "DB" + database_name = "DATABASE_NAME" + database_id = "DATABASE_ID" +``` + +In the above configuration: + +- `[[something.abc]]` creates an object `something` with a property `abc` (which is an object itself). +- Any property below the line in the form ` = ` is a property of the `abc` object. + +Therefore, the above binding is equivalent to: + +```json +{ + "something": { + "abc": [ + { + "binding": "DB", + "database_name": "DATABASE_NAME", + "database_id": "DATABASE_ID" + } + ] + } +} +``` + +### Example + +```toml +[[env.staging.d1_databases]] + binding = "BINDING_NAME_1" + database_name = "DATABASE_NAME_1" + database_id = "UUID_1" + +[[env.production.d1_databases]] + binding = "BINDING_NAME_2" + database_name = "DATABASE_NAME_2" + database_id = "UUID_2" + +``` + +The above is equivalent to the following structure in JSON: + +```json +{ + "env": { + "staging": { + "d1_databases": [ + { + "binding": "BINDING_NAME_1", + "database_id": "PRODUCTION_DATABASE_1", + "database_name": "UUID_1" + } + ] + }, + "production": { + "d1_databases": [ + { + "binding": "BINDING_NAME_2", + "database_name": "DATABASE_NAME_2", + "database_id": "UUID_2" + } + ] + } + } + } +} +``` From 6a3b01d528f79b42f706c2f13e25e561296de84e Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 12:22:41 +0000 Subject: [PATCH 2/7] Changing names to be more specific/relevant. --- src/content/docs/d1/configuration/environments.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index 21b047c925cd38f..9bf7f4a678b010c 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -31,7 +31,7 @@ In the code above, the `staging` environment is using a different database (`DAT If you have multiple environments in your D1 binding, your `wrangler.toml` may look like the following: ```toml -[[env.abc]] +[[production.d1_databases]] binding = "DB" database_name = "DATABASE_NAME" database_id = "DATABASE_ID" @@ -39,15 +39,15 @@ If you have multiple environments in your D1 binding, your `wrangler.toml` may l In the above configuration: -- `[[something.abc]]` creates an object `something` with a property `abc` (which is an object itself). -- Any property below the line in the form ` = ` is a property of the `abc` object. +- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases` (which is an object itself). +- Any property below the line in the form ` = ` is a property of the `d1_databases` object. Therefore, the above binding is equivalent to: ```json { - "something": { - "abc": [ + "production": { + "d1_databases": [ { "binding": "DB", "database_name": "DATABASE_NAME", From cd53dc2e5cfdcf54d1ea48bf8ea6ae515597653c Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 12:29:20 +0000 Subject: [PATCH 3/7] Fixing formatting. Clarifying wording. --- .../docs/d1/configuration/environments.mdx | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index 9bf7f4a678b010c..e3727ecad8682e5 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -28,19 +28,19 @@ In the code above, the `staging` environment is using a different database (`DAT ## Anatomy of `wrangler.toml` file -If you have multiple environments in your D1 binding, your `wrangler.toml` may look like the following: +If you need to specify different D1 databases for different environments, your `wrangler.toml` may look like the following: ```toml [[production.d1_databases]] - binding = "DB" - database_name = "DATABASE_NAME" - database_id = "DATABASE_ID" +binding = "DB" +database_name = "DATABASE_NAME" +database_id = "DATABASE_ID" ``` In the above configuration: -- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases` (which is an object itself). -- Any property below the line in the form ` = ` is a property of the `d1_databases` object. +- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects. +- Any property below the line in the form ` = ` is a property of an object within the `d1_databases` array. Therefore, the above binding is equivalent to: @@ -62,14 +62,14 @@ Therefore, the above binding is equivalent to: ```toml [[env.staging.d1_databases]] - binding = "BINDING_NAME_1" - database_name = "DATABASE_NAME_1" - database_id = "UUID_1" +binding = "BINDING_NAME_1" +database_name = "DATABASE_NAME_1" +database_id = "UUID_1" [[env.production.d1_databases]] - binding = "BINDING_NAME_2" - database_name = "DATABASE_NAME_2" - database_id = "UUID_2" +binding = "BINDING_NAME_2" +database_name = "DATABASE_NAME_2" +database_id = "UUID_2" ``` @@ -78,25 +78,24 @@ The above is equivalent to the following structure in JSON: ```json { "env": { + "production": { + "d1_databases": [ + { + "binding": "BINDING_NAME_2", + "database_id": "UUID_2", + "database_name": "DATABASE_NAME_2" + } + ] + }, "staging": { "d1_databases": [ { "binding": "BINDING_NAME_1", - "database_id": "PRODUCTION_DATABASE_1", - "database_name": "UUID_1" + "database_id": "UUID_1", + "database_name": "DATABASE_NAME_1" } ] - }, - "production": { - "d1_databases": [ - { - "binding": "BINDING_NAME_2", - "database_name": "DATABASE_NAME_2", - "database_id": "UUID_2" - } - ] - } - } + } } } ``` From fe213618fa7058ed3fae620079105b5468820be5 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 12:30:44 +0000 Subject: [PATCH 4/7] Wording clarity --- src/content/docs/d1/configuration/environments.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index e3727ecad8682e5..cc58ff50106b863 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -28,7 +28,7 @@ In the code above, the `staging` environment is using a different database (`DAT ## Anatomy of `wrangler.toml` file -If you need to specify different D1 databases for different environments, your `wrangler.toml` may look like the following: +If you need to specify different D1 databases for different environments, your `wrangler.toml` may contain bindings that resemble the following: ```toml [[production.d1_databases]] From 7d561d233e1757c2e9d284307c9b138afb09e27b Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 12:37:36 +0000 Subject: [PATCH 5/7] Update src/content/docs/d1/configuration/environments.mdx Co-authored-by: Lambros Petrou --- src/content/docs/d1/configuration/environments.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index cc58ff50106b863..ae682c817a54c78 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -39,7 +39,7 @@ database_id = "DATABASE_ID" In the above configuration: -- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects. +- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects, since you can create multiple D1 bindings in case you have more than one databases. - Any property below the line in the form ` = ` is a property of an object within the `d1_databases` array. Therefore, the above binding is equivalent to: From 5ad682755a5382bfbe7b83c1107df0b268e4e261 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 13:29:27 +0000 Subject: [PATCH 6/7] Replacing tabs with spaces. --- .../docs/d1/configuration/environments.mdx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index cc58ff50106b863..7eaba616ee1b94d 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -46,15 +46,15 @@ Therefore, the above binding is equivalent to: ```json { - "production": { - "d1_databases": [ - { - "binding": "DB", - "database_name": "DATABASE_NAME", - "database_id": "DATABASE_ID" - } - ] - } + "production": { + "d1_databases": [ + { + "binding": "DB", + "database_name": "DATABASE_NAME", + "database_id": "DATABASE_ID" + } + ] + } } ``` From 085626b9724775f2610c6da63a0934b56a333fb1 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Wed, 13 Nov 2024 13:31:17 +0000 Subject: [PATCH 7/7] Update src/content/docs/d1/configuration/environments.mdx Co-authored-by: Pedro Sousa <680496+pedrosousa@users.noreply.github.com> --- src/content/docs/d1/configuration/environments.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/d1/configuration/environments.mdx b/src/content/docs/d1/configuration/environments.mdx index 88c0c030dc1a899..d7652b001deac75 100644 --- a/src/content/docs/d1/configuration/environments.mdx +++ b/src/content/docs/d1/configuration/environments.mdx @@ -39,7 +39,7 @@ database_id = "DATABASE_ID" In the above configuration: -- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects, since you can create multiple D1 bindings in case you have more than one databases. +- `[[production.d1_databases]]` creates an object `production` with a property `d1_databases`, where `d1_databases` is an array of objects, since you can create multiple D1 bindings in case you have more than one database. - Any property below the line in the form ` = ` is a property of an object within the `d1_databases` array. Therefore, the above binding is equivalent to: