Skip to content

Commit 5ea86ca

Browse files
authored
Add new_sqlite_classes migration for Durable Objects (#6606)
1 parent 1a4b4ba commit 5ea86ca

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

packages/wrangler/src/__tests__/configuration.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ describe("normalizeAndValidateConfig()", () => {
16741674
{
16751675
tag: "TAG",
16761676
new_classes: ["CLASS_1", "CLASS_2"],
1677+
new_sqlite_classes: ["CLASS_1", "CLASS_2"],
16771678
renamed_classes: [
16781679
{
16791680
from: "FROM_CLASS",
@@ -1702,6 +1703,7 @@ describe("normalizeAndValidateConfig()", () => {
17021703
{
17031704
tag: 111,
17041705
new_classes: [222, 333],
1706+
new_sqlite_classes: [222, 333],
17051707
renamed_classes: [
17061708
{
17071709
from: 444,
@@ -1726,6 +1728,8 @@ describe("normalizeAndValidateConfig()", () => {
17261728
- Expected \\"migrations[0].tag\\" to be of type string but got 111.
17271729
- Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
17281730
- Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
1731+
- Expected \\"migrations[0].new_sqlite_classes.[0]\\" to be of type string but got 222.
1732+
- Expected \\"migrations[0].new_sqlite_classes.[1]\\" to be of type string but got 333.
17291733
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
17301734
- Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
17311735
- Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
@@ -4456,6 +4460,7 @@ describe("normalizeAndValidateConfig()", () => {
44564460
{
44574461
tag: 111,
44584462
new_classes: [222, 333],
4463+
new_sqlite_classes: [222, 333],
44594464
renamed_classes: [
44604465
{
44614466
from: 444,
@@ -4482,6 +4487,8 @@ describe("normalizeAndValidateConfig()", () => {
44824487
- Expected \\"migrations[0].tag\\" to be of type string but got 111.
44834488
- Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
44844489
- Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
4490+
- Expected \\"migrations[0].new_sqlite_classes.[0]\\" to be of type string but got 222.
4491+
- Expected \\"migrations[0].new_sqlite_classes.[1]\\" to be of type string but got 333.
44854492
- Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
44864493
- Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
44874494
- Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7415,6 +7415,54 @@ addEventListener('fetch', event => {});`
74157415
expect(std.warn).toMatchInlineSnapshot(`""`);
74167416
});
74177417

7418+
it("should support durable object bindings to SQLite classes", async () => {
7419+
writeWranglerToml({
7420+
durable_objects: {
7421+
bindings: [
7422+
{
7423+
name: "EXAMPLE_DO_BINDING",
7424+
class_name: "ExampleDurableObject",
7425+
},
7426+
],
7427+
},
7428+
migrations: [
7429+
{ tag: "v1", new_sqlite_classes: ["ExampleDurableObject"] },
7430+
],
7431+
});
7432+
fs.writeFileSync(
7433+
"index.js",
7434+
`export class ExampleDurableObject {}; export default{};`
7435+
);
7436+
mockSubDomainRequest();
7437+
mockLegacyScriptData({
7438+
scripts: [{ id: "test-name", migration_tag: "v1" }],
7439+
});
7440+
mockUploadWorkerRequest({
7441+
expectedBindings: [
7442+
{
7443+
class_name: "ExampleDurableObject",
7444+
name: "EXAMPLE_DO_BINDING",
7445+
type: "durable_object_namespace",
7446+
},
7447+
],
7448+
});
7449+
7450+
await runWrangler("deploy index.js");
7451+
expect(std.out).toMatchInlineSnapshot(`
7452+
"Total Upload: xx KiB / gzip: xx KiB
7453+
Worker Startup Time: 100 ms
7454+
Your worker has access to the following bindings:
7455+
- Durable Objects:
7456+
- EXAMPLE_DO_BINDING: ExampleDurableObject
7457+
Uploaded test-name (TIMINGS)
7458+
Deployed test-name triggers (TIMINGS)
7459+
https://test-name.test-sub-domain.workers.dev
7460+
Current Version ID: Galaxy-Class"
7461+
`);
7462+
expect(std.err).toMatchInlineSnapshot(`""`);
7463+
expect(std.warn).toMatchInlineSnapshot(`""`);
7464+
});
7465+
74187466
it("should support service-workers binding to external durable objects", async () => {
74197467
writeWranglerToml({
74207468
durable_objects: {

packages/wrangler/src/config/environment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ interface EnvironmentInheritable {
188188
tag: string;
189189
/** The new Durable Objects being defined. */
190190
new_classes?: string[];
191+
/** The new SQLite Durable Objects being defined. */
192+
new_sqlite_classes?: string[];
191193
/** The Durable Objects being renamed. */
192194
renamed_classes?: {
193195
from: string;

packages/wrangler/src/config/validation.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,8 +3144,14 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => {
31443144

31453145
let valid = true;
31463146
for (let i = 0; i < rawMigrations.length; i++) {
3147-
const { tag, new_classes, renamed_classes, deleted_classes, ...rest } =
3148-
rawMigrations[i];
3147+
const {
3148+
tag,
3149+
new_classes,
3150+
new_sqlite_classes,
3151+
renamed_classes,
3152+
deleted_classes,
3153+
...rest
3154+
} = rawMigrations[i];
31493155

31503156
valid =
31513157
validateAdditionalProperties(
@@ -3172,6 +3178,14 @@ const validateMigrations: ValidatorFn = (diagnostics, field, value) => {
31723178
"string"
31733179
) && valid;
31743180

3181+
valid =
3182+
validateOptionalTypedArray(
3183+
diagnostics,
3184+
`migrations[${i}].new_sqlite_classes`,
3185+
new_sqlite_classes,
3186+
"string"
3187+
) && valid;
3188+
31753189
if (renamed_classes !== undefined) {
31763190
if (!Array.isArray(renamed_classes)) {
31773191
diagnostics.errors.push(

packages/wrangler/src/deployment-bundle/worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export interface CfDurableObjectMigrations {
256256
new_tag: string;
257257
steps: {
258258
new_classes?: string[];
259+
new_sqlite_classes?: string[];
259260
renamed_classes?: {
260261
from: string;
261262
to: string;

0 commit comments

Comments
 (0)