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
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.
12
11
@@ -32,41 +31,48 @@ Updating the code for an existing Durable Object class does not require a migrat
32
31
33
32
The most common migration performed is a new class migration, which informs the runtime that a new Durable Object class is being uploaded. This is also the migration you need when creating your first Durable Object class.
34
33
35
-
To apply a Create migration, add the following lines to your `wrangler.toml / wrangler.json` file:
34
+
To apply a Create migration:
36
35
37
-
<WranglerConfig>
38
-
```toml
39
-
[[migrations]]
40
-
tag = "<v1>"# Migration identifier. This should be unique for each migration entry
41
-
new_classes = ["<NewDurableObjectClass>"] # Array of new classes
42
-
# For SQLite storage backend use new_sqlite_classes=["<NewDurableObjectClass>"] instead
43
-
```
44
-
</WranglerConfig>
36
+
<Steps>
37
+
1. Add the following lines to your `wrangler.toml / wrangler.json` file:
45
38
46
-
### Create migration example
39
+
<WranglerConfig>
40
+
```toml
41
+
[[migrations]]
42
+
tag = "<v1>"# Migration identifier. This should be unique for each migration entry
43
+
new_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:
47
48
48
-
If you are creating two new Durable Object bindings, your `wrangler.toml / wrangler.json` file should look like the following:
49
+
- A `tag` to identify the migration.
50
+
- The array `new_classes`, which contains the new Durable Object class.
49
51
50
-
<WranglerConfig>
52
+
2. Ensure you reference the correct name of the Durable Object class in your Worker code.
53
+
3. Deploy the Worker.
54
+
</Steps>
55
+
56
+
<Detailsheader="Create migration example">
57
+
58
+
To create a new Durable Object binding `DURABLE_OBJECT_A`, your `wrangler.toml / wrangler.json` file should look like the following:
Running a Delete migration will delete all Durable Objects associated with the deleted class, including all of their stored data.
@@ -75,91 +81,98 @@ Running a Delete migration will delete all Durable Objects associated with the d
75
81
- Copy any important data to some other location before deleting.
76
82
- You do not have to run a Delete migration on a class that was renamed or transferred.
77
83
78
-
To apply a Delete migration, add the following lines to your `wrangler.toml / wrangler.json` file:
84
+
To apply a Delete migration:
79
85
80
-
<WranglerConfig>
81
-
```toml
82
-
[[migrations]]
83
-
tag = "<v2>"# Migration identifier. This should be unique for each migration entry
84
-
deleted_classes = ["<ClassToDelete>"] # Array of deleted class names
85
-
```
86
-
</WranglerConfig>
86
+
<Steps>
87
+
1. Remove the binding for the class you wish to delete from the `wrangler.toml / wrangler.json` file.
88
+
2. Remove references for the class you wish to delete from your Worker code.
89
+
3. Add the following lines to your `wrangler.toml / wrangler.json` file.
87
90
88
-
### Delete migration example
91
+
<WranglerConfig>
92
+
```toml
93
+
[[migrations]]
94
+
tag = "<v2>"# Migration identifier. This should be unique for each migration entry
95
+
deleted_classes = ["<ClassToDelete>"] # Array of deleted class names
96
+
```
97
+
</WranglerConfig>
98
+
The Delete migration contains:
89
99
90
-
To run the Delete migration:
100
+
- A `tag` to identify the migration.
101
+
- The array `deleted_classes`, which contains the deleted Durable Object classes.
102
+
4. Deploy the Worker.
103
+
</Steps>
91
104
92
-
- Remove the binding for the `DeprecatedClass`
93
-
- Deploy the Worker
105
+
<Detailsheader="Delete migration example">
106
+
To delete a Durable Object binding `DEPRECATED_OBJECT`, your `wrangler.toml / wrangler.json` file should look like the following:
94
107
95
108
<WranglerConfig>
96
-
97
109
```toml
98
-
# Remove the binding for the DeprecatedClass DO
99
-
[[durable_objects.bindings]]
100
-
name = "MY_DURABLE_OBJECT"
101
-
class_name = "MyDurableObjectClass"
102
-
110
+
# Remove the binding for the DeprecatedObjectClass DO
111
+
#[[durable_objects.bindings]]
112
+
#name = "DEPRECATED_OBJECT"
113
+
#class_name = "DeprecatedObjectClass"
103
114
104
115
[[migrations]]
105
-
tag = "v1"# Should be unique for each entry
106
-
new_classes = ["DeprecatedClass","MyDurableObjectClass"] # Array of new classes
116
+
tag = "v3"# Should be unique for each entry
117
+
deleted_classes = ["DeprecatedObjectClass"] # Array of new classes
107
118
```
108
-
109
119
</WranglerConfig>
110
-
111
-
If you just want to run the Delete migration, add the Delete migration configuration and deploy the Worker.
120
+
</Details>
112
121
113
122
## Rename migration
114
123
115
124
Rename migrations are used to transfer stored Durable Objects between two Durable Object classes in the same Worker code file.
116
125
117
-
To apply a Rename migration, edit your `wrangler.toml / wrangler.json` file in the following way:
126
+
To apply a Rename migration:
127
+
128
+
<Steps>
129
+
1. Update the previous class name to the new class name by editing your `wrangler.toml / wrangler.json` file in the following way:
130
+
131
+
<WranglerConfig>
132
+
```toml
133
+
[[durable_objects.bindings]]
134
+
name = "<MY_DURABLE_OBJECT>"
135
+
class_name = "<UpdatedDurableObject>"# Update the class name to the new class name
136
+
137
+
[[migrations]]
138
+
tag = "<v3>"# Migration identifier. This should be unique for each migration entry
139
+
renamed_classes = [{from = "<OldDurableObject>", to = "<UpdatedDurableObject>" }] # Array of rename directives
140
+
```
141
+
</WranglerConfig>
142
+
The Rename migration contains:
143
+
- A `tag` to identify the migration.
144
+
- The `renamed_classes` array, which contains objects with `from` and `to` properties.
145
+
- `from` property is the name of the old Durable Object class.
146
+
- `to` property is the name of the renamed Durable Object class.
147
+
2. Reference the new Durable Object class name in your Worker code.
148
+
3. Deploy the Worker.
149
+
</Steps>
118
150
119
-
<WranglerConfig>
120
-
```toml
121
-
[[durable_objects.bindings]]
122
-
name = "<MY_DURABLE_OBJECT>"
123
-
class_name = "<UpdatedDurableObject>"# Update the class name to the new class name
124
-
125
-
[[migrations]]
126
-
tag = "<v2>"# Migration identifier. This should be unique for each migration entry
127
-
renamed_classes = [{from = "<OldDurableObject>", to = "<UpdatedDurableObject>" }] # Array of rename directives
128
-
```
129
-
</WranglerConfig>
130
-
131
-
### Rename migration example
132
-
133
-
To run Rename migration:
151
+
:::note
152
+
To apply both migrations in the same deploy, add the migrations configuration and deploy the Worker.
153
+
:::
134
154
135
-
- Update the binding for the `DurableObjectExample` to the new class name `UpdatedName`
136
-
- Add the Rename migration configuration
137
-
- Deploy the Worker
155
+
<Detailsheader="Rename migration example">
138
156
139
-
To apply both migrations in the same deploy, add the migrations configuration and deploy the Worker.
157
+
To rename a Durable Object class, from `OldName` to `UpdatedName`, your `wrangler.toml / wrangler.json` file should look like the following:
140
158
141
159
<WranglerConfig>
142
-
143
160
```toml
144
161
# Before deleting the `DeprecatedClass` remove the binding for the `DeprecatedClass`.
145
162
# Update the binding for the `DurableObjectExample` to the new class name `UpdatedName`.
146
163
[[durable_objects.bindings]]
147
164
name = "MY_DURABLE_OBJECT"
148
165
class_name = "UpdatedName"
149
166
167
+
# Renaming classes
150
168
[[migrations]]
151
-
tag = "v1"# Should be unique for each entry
152
-
new_classes = ["DeprecatedClass","DurableObjectExample"] # Array of new classes
153
-
154
-
# Renaming and deleting classes
155
-
[[migrations]]
156
-
tag = "v2"
157
-
renamed_classes = [{from = "DurableObjectExample", to = "UpdatedName" }] # Array of rename directives
158
-
deleted_classes = ["DeprecatedClass"] # Array of deleted class names
169
+
tag = "v3"
170
+
renamed_classes = [{from = "OldName", to = "UpdatedName" }] # Array of rename directives
159
171
```
160
-
161
172
</WranglerConfig>
162
173
174
+
</Details>
175
+
163
176
## Transfer migration
164
177
165
178
Transfer migrations are used to transfer stored Durable Objects between two Durable Object classes in different Worker code files.
@@ -170,33 +183,45 @@ If you want to transfer stored Durable Objects between two Durable Object classe
170
183
Do not run a [Create migration](#create-migration) for the destination class before running a Transfer migration. The Transfer migration will create the destination class for you.
171
184
:::
172
185
173
-
### Transfer migration example
174
-
175
-
To apply a Transfer migration, edit your `wrangler.toml / wrangler.json` file in the following way:
176
-
177
-
<WranglerConfig>
178
-
```toml
179
-
[[durable_objects.bindings]]
180
-
name = "<MY_DURABLE_OBJECT>"
181
-
class_name = "<DestinationDurableObjectClass>"
182
-
183
-
[[migrations]]
184
-
tag = "<v1>"# Migration identifier. This should be unique for each migration entry
- The `transferred_class` array, which contains objects with `from`, `from_script`, and `to` properties.
205
+
- `from` property is the name of the source Durable Object class.
206
+
- `from_script` property is the name of the source Worker script.
207
+
- `to` property is the name of the destination Durable Object class.
208
+
2. Ensure you reference the name of the new, destination Durable Object class in your Worker code.
209
+
3. Deploy the Worker.
210
+
</Steps>
188
211
189
212
:::caution[Important]
190
213
- The destination class (the class that stored Durable Objects are being transferred to) for a Rename or Transfer migration must be exported by the deployed Worker.
191
214
192
-
- You don't have to create the destination Durable Object class before running a Rename or Transfer migration. The migration will create the destination class for you.
215
+
- You should not create the destination Durable Object class before running a Rename or Transfer migration. The migration will create the destination class for you.
193
216
194
217
- After a Rename or Transfer migration, requests to the destination Durable Object class will have access to the source Durable Object's stored data.
195
218
196
219
- After a migration, any existing bindings to the original Durable Object class (for example, from other Workers) will automatically forward to the updated destination class. However, any Workers bound to the updated Durable Object class must update their Durable Object binding configuration in the `wrangler` configuration file for their next deployment.
197
220
:::
198
221
199
-
You can transfer stored Durable Objects from `DurableObjectExample` to `TransferredClass` from a Worker script named `OldWorkerScript`. The configuration of the `wrangler` file for your new Worker code (destination Worker code) would look like this:
222
+
<Detailsheader="Transfer migration example">
223
+
224
+
You can transfer stored Durable Objects from `DurableObjectExample` to `TransferredClass` from a Worker script named `OldWorkerScript`. The configuration of the `wrangler.toml / wrangler.json` file for your new Worker code (destination Worker code) would look like this:
## Durable Object migrations configuration in the Wrangler configuration file
217
242
218
243
- Migrations are performed through the `[[migrations]]` configurations key in your `wrangler.toml` file or `migration` key in your `wrangler.json` file.
0 commit comments