You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
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.
11
17
@@ -36,18 +42,18 @@ To apply a Create migration:
36
42
<Steps>
37
43
1. Add the following lines to your `wrangler.toml / wrangler.json` file:
38
44
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:
48
54
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.
51
57
52
58
2. Ensure you reference the correct name of the Durable Object class in your Worker code.
53
59
3. Deploy the Worker.
@@ -65,9 +71,11 @@ name = "DURABLE_OBJECT_A"
65
71
class_name = "DurableObjectAClass"
66
72
67
73
# Add the lines below for a Create migration.
74
+
68
75
[[migrations]]
69
76
tag = "v1"
70
77
new_sqlite_classes = ["DurableObjectAClass"]
78
+
71
79
```
72
80
</WranglerConfig>
73
81
@@ -93,7 +101,7 @@ new_classes = ["MyDurableObject"] # Array of new classes
93
101
94
102
</WranglerConfig>
95
103
96
-
<Renderfile="do-plans-note"/>
104
+
<Renderfile="do-plans-note"/>
97
105
98
106
## Delete migration
99
107
@@ -110,17 +118,18 @@ To apply a Delete migration:
110
118
2. Remove references for the class you wish to delete from your Worker code.
111
119
3. Add the following lines to your `wrangler.toml / wrangler.json` file.
112
120
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.
121
132
122
-
- A `tag` to identify the migration.
123
-
- The array `deleted_classes`, which contains the deleted Durable Object classes.
124
133
4. Deploy the Worker.
125
134
</Steps>
126
135
@@ -137,6 +146,7 @@ To delete a Durable Object binding `DEPRECATED_OBJECT`, your `wrangler.toml / wr
137
146
[[migrations]]
138
147
tag = "v3"# Should be unique for each entry
139
148
deleted_classes = ["DeprecatedObjectClass"] # Array of deleted classes
149
+
140
150
```
141
151
</WranglerConfig>
142
152
</Details>
@@ -188,6 +198,7 @@ class_name = "UpdatedName"
188
198
tag = "v3"
189
199
renamed_classes = [{from = "OldName", to = "UpdatedName" }] # Array of rename directives
190
200
```
201
+
191
202
</WranglerConfig>
192
203
193
204
</Details>
@@ -207,23 +218,24 @@ To apply a Transfer migration:
207
218
<Steps>
208
219
1. Edit your `wrangler.toml / wrangler.json` file in the following way:
209
220
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
- 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.
257
271
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.
259
292
260
293
- All migrations are applied at deployment. Each migration can only be applied once per [environment](/durable-objects/reference/environments/).
261
294
@@ -279,4 +312,5 @@ You cannot enable a SQLite storage backend on an existing, deployed Durable Obje
279
312
280
313
:::caution[Important]
281
314
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.
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/reference/environments.mdx
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,12 @@ durable_objects.bindings = [
61
61
62
62
</WranglerConfig>
63
63
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
+
64
70
## Local development
65
71
66
72
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