Skip to content

Commit cfe6c4c

Browse files
joshthowardOxyjunvy-ton
authored
Remove incorrect statement that migrations are not environment specific (#22394)
* Remove incorrect statement that migrations are not environment specific * Fixing Steps component to fix CI * Fixing too many backticks on Wrangler snippets * Adding migration inheritance detail. * Separating out into separate bullet point. * Adding more detail, addressing VT feedback. * Update src/content/docs/durable-objects/reference/durable-objects-migrations.mdx Co-authored-by: Vy Ton <[email protected]> --------- Co-authored-by: Jun Lee <[email protected]> Co-authored-by: Vy Ton <[email protected]>
1 parent d65eeea commit cfe6c4c

File tree

2 files changed

+81
-41
lines changed

2 files changed

+81
-41
lines changed

src/content/docs/durable-objects/reference/durable-objects-migrations.mdx

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ sidebar:
55
order: 2
66
---
77

8-
import { Render, GlossaryTooltip, WranglerConfig, Steps, Details } from "~/components";
8+
import {
9+
Render,
10+
GlossaryTooltip,
11+
WranglerConfig,
12+
Steps,
13+
Details,
14+
} from "~/components";
915

1016
A migration is a mapping process from a class name to a runtime state. This process communicates the changes to the Workers runtime and provides the runtime with instructions on how to deal with those changes.
1117

@@ -36,18 +42,18 @@ To apply a Create migration:
3642
<Steps>
3743
1. Add the following lines to your `wrangler.toml / wrangler.json` file:
3844

39-
<WranglerConfig>
40-
```toml
41-
[[migrations]]
42-
tag = "<v1>" # Migration identifier. This should be unique for each migration entry
43-
new_sqlite_classes = ["<NewDurableObjectClass>"] # Array of new classes
44-
# For SQLite storage backend use new_sqlite_classes=["<NewDurableObjectClass>"] instead
45-
```
46-
</WranglerConfig>
47-
The Create migration contains:
45+
<WranglerConfig>
46+
```toml
47+
[[migrations]]
48+
tag = "<v1>" # Migration identifier. This should be unique for each migration entry
49+
new_sqlite_classes = ["<NewDurableObjectClass>"] # Array of new classes
50+
# For SQLite storage backend use new_sqlite_classes=["<NewDurableObjectClass>"] instead
51+
```
52+
</WranglerConfig>
53+
The Create migration contains:
4854

49-
- A `tag` to identify the migration.
50-
- The array `new_sqlite_classes`, which contains the new Durable Object class.
55+
- A `tag` to identify the migration.
56+
- The array `new_sqlite_classes`, which contains the new Durable Object class.
5157

5258
2. Ensure you reference the correct name of the Durable Object class in your Worker code.
5359
3. Deploy the Worker.
@@ -65,9 +71,11 @@ name = "DURABLE_OBJECT_A"
6571
class_name = "DurableObjectAClass"
6672

6773
# Add the lines below for a Create migration.
74+
6875
[[migrations]]
6976
tag = "v1"
7077
new_sqlite_classes = ["DurableObjectAClass"]
78+
7179
```
7280
</WranglerConfig>
7381

@@ -93,7 +101,7 @@ new_classes = ["MyDurableObject"] # Array of new classes
93101

94102
</WranglerConfig>
95103

96-
<Render file="do-plans-note"/>
104+
<Render file="do-plans-note" />
97105

98106
## Delete migration
99107

@@ -110,17 +118,18 @@ To apply a Delete migration:
110118
2. Remove references for the class you wish to delete from your Worker code.
111119
3. Add the following lines to your `wrangler.toml / wrangler.json` file.
112120

113-
<WranglerConfig>
114-
```toml
115-
[[migrations]]
116-
tag = "<v2>" # Migration identifier. This should be unique for each migration entry
117-
deleted_classes = ["<ClassToDelete>"] # Array of deleted class names
118-
```
119-
</WranglerConfig>
120-
The Delete migration contains:
121+
<WranglerConfig>
122+
```toml
123+
[[migrations]]
124+
tag = "<v2>" # Migration identifier. This should be unique for each migration entry
125+
deleted_classes = ["<ClassToDelete>"] # Array of deleted class names
126+
```
127+
</WranglerConfig>
128+
The Delete migration contains:
129+
130+
- A `tag` to identify the migration.
131+
- The array `deleted_classes`, which contains the deleted Durable Object classes.
121132

122-
- A `tag` to identify the migration.
123-
- The array `deleted_classes`, which contains the deleted Durable Object classes.
124133
4. Deploy the Worker.
125134
</Steps>
126135

@@ -137,6 +146,7 @@ To delete a Durable Object binding `DEPRECATED_OBJECT`, your `wrangler.toml / wr
137146
[[migrations]]
138147
tag = "v3" # Should be unique for each entry
139148
deleted_classes = ["DeprecatedObjectClass"] # Array of deleted classes
149+
140150
```
141151
</WranglerConfig>
142152
</Details>
@@ -188,6 +198,7 @@ class_name = "UpdatedName"
188198
tag = "v3"
189199
renamed_classes = [{from = "OldName", to = "UpdatedName" }] # Array of rename directives
190200
```
201+
191202
</WranglerConfig>
192203

193204
</Details>
@@ -207,23 +218,24 @@ To apply a Transfer migration:
207218
<Steps>
208219
1. Edit your `wrangler.toml / wrangler.json` file in the following way:
209220

210-
<WranglerConfig>
211-
```toml
212-
[[durable_objects.bindings]]
213-
name = "<MY_DURABLE_OBJECT>"
214-
class_name = "<DestinationDurableObjectClass>"
221+
<WranglerConfig>
222+
```toml
223+
[[durable_objects.bindings]]
224+
name = "<MY_DURABLE_OBJECT>"
225+
class_name = "<DestinationDurableObjectClass>"
226+
227+
[[migrations]]
228+
tag = "<v4>" # Migration identifier. This should be unique for each migration entry
229+
transferred_classes = [{from = "<SourceDurableObjectClass>", from_script = "<SourceWorkerScript>", to = "<DestinationDurableObjectClass>" }]
230+
```
231+
</WranglerConfig>
232+
The Transfer migration contains:
233+
- A `tag` to identify the migration.
234+
- The `transferred_class` array, which contains objects with `from`, `from_script`, and `to` properties.
235+
- `from` property is the name of the source Durable Object class.
236+
- `from_script` property is the name of the source Worker script.
237+
- `to` property is the name of the destination Durable Object class.
215238

216-
[[migrations]]
217-
tag = "<v4>" # Migration identifier. This should be unique for each migration entry
218-
transferred_classes = [{from = "<SourceDurableObjectClass>", from_script = "<SourceWorkerScript>", to = "<DestinationDurableObjectClass>" }]
219-
```
220-
</WranglerConfig>
221-
The Transfer migration contains:
222-
- A `tag` to identify the migration.
223-
- The `transferred_class` array, which contains objects with `from`, `from_script`, and `to` properties.
224-
- `from` property is the name of the source Durable Object class.
225-
- `from_script` property is the name of the source Worker script.
226-
- `to` property is the name of the destination Durable Object class.
227239
2. Ensure you reference the name of the new, destination Durable Object class in your Worker code.
228240
3. Deploy the Worker.
229241
</Steps>
@@ -240,9 +252,11 @@ name = "MY_DURABLE_OBJECT"
240252
class_name = "TransferredClass"
241253

242254
# Transferring class
255+
243256
[[migrations]]
244257
tag = "v4"
245258
transferred_classes = [{from = "DurableObjectExample", from_script = "OldWorkerScript", to = "TransferredClass" }]
259+
246260
```
247261
</WranglerConfig>
248262

@@ -255,7 +269,26 @@ transferred_classes = [{from = "DurableObjectExample", from_script = "OldWorkerS
255269

256270
- Migration tags are treated like unique names and are used to determine which migrations have already been applied. Once a given Worker code has a migration tag set on it, all future Worker code deployments must include a migration tag.
257271

258-
- The migration list is an ordered array of tables, specified as a top-level key in your `wrangler` configuration file. The migration list is inherited by all environments and cannot be overridden by a specific environment.
272+
- The migration list is an ordered array of tables, specified as a key in your Wrangler configuration file.
273+
274+
- You can define the migration for each environment, as well as at the top level.
275+
- Top-level migration is specified at the top-level `migrations` key in the Wrangler configuration file.
276+
- Environment-level migration is specified by a `migrations` key inside the `env` key of the Wrangler configuration file (`[env.<environment_name>.migrations]`).
277+
- Example Wrangler file:
278+
```jsonc title="wrangler.jsonc"
279+
{
280+
// top-level default migrations
281+
"migrations": [{ ... }],
282+
"env": {
283+
"staging": {
284+
// migration override for staging
285+
"migrations": [{...}]
286+
}
287+
}
288+
}
289+
```
290+
- If a migration is only specified at the top-level, but not at the environment-level, the environment will inherit the top-level migration.
291+
- Migrations at at the environment-level override migrations at the top level.
259292

260293
- All migrations are applied at deployment. Each migration can only be applied once per [environment](/durable-objects/reference/environments/).
261294

@@ -279,4 +312,5 @@ You cannot enable a SQLite storage backend on an existing, deployed Durable Obje
279312

280313
:::caution[Important]
281314
Durable Object migrations are atomic operations and cannot be gradually deployed. To provide early feedback to developers, new Worker versions with new migrations cannot be uploaded. Refer to [Gradual deployments for Durable Objects](/workers/configuration/versions-and-deployments/gradual-deployments/#gradual-deployments-for-durable-objects) for more information.
282-
:::
315+
:::
316+

src/content/docs/durable-objects/reference/environments.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ durable_objects.bindings = [
6161

6262
</WranglerConfig>
6363

64+
### Migration environments
65+
66+
You can define a Durable Object migration for each environment, as well as at the top level. Migrations at at the environment-level override migrations at the top level.
67+
68+
For more information, refer to [Migration Wrangler Configuration](/durable-objects/reference/durable-objects-migrations/#migration-wrangler-configuration).
69+
6470
## Local development
6571

6672
Local development sessions create a standalone, local-only environment that mirrors the production environment, so that you can test your Worker and Durable Objects before you deploy to production.

0 commit comments

Comments
 (0)