-
Notifications
You must be signed in to change notification settings - Fork 1k
check if there are any pending DO migrations for a worker #11096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nikitassharma
wants to merge
8
commits into
main
Choose a base branch
from
nsharma/check-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+360
−16
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0cb1140
add `wrangler check do-migration` command
nikitassharma c453e68
add tests for do migration check
nikitassharma a8cba32
changeset
nikitassharma 315f3f8
prettify
nikitassharma 3a2fd2b
checks
nikitassharma ed18385
fix test
nikitassharma 4ab895d
fixed?
nikitassharma 3b19247
Merge branch 'main' into nsharma/check-migration
nikitassharma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| Adds `wrangler check do-migration` to check if there are any pending DO migrations for a worker. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
242 changes: 242 additions & 0 deletions
242
packages/wrangler/src/__tests__/do-migration-check.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| import { mockAccountId, mockApiToken } from "./helpers/mock-account-id"; | ||
| import { mockConsoleMethods } from "./helpers/mock-console"; | ||
| import { useMockIsTTY } from "./helpers/mock-istty"; | ||
| import { mockLegacyScriptData } from "./helpers/mock-legacy-script"; | ||
| import { runInTempDir } from "./helpers/run-in-tmp"; | ||
| import { runWrangler } from "./helpers/run-wrangler"; | ||
| import { writeWranglerConfig } from "./helpers/write-wrangler-config"; | ||
|
|
||
| describe("wrangler check do-migrations", () => { | ||
| mockAccountId(); | ||
| mockApiToken(); | ||
| runInTempDir(); | ||
| const { setIsTTY } = useMockIsTTY(); | ||
| const std = mockConsoleMethods(); | ||
|
|
||
| beforeEach(() => { | ||
| setIsTTY(true); | ||
| }); | ||
|
|
||
| test("it can list a pending DO migration", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMENAME", class_name: "SomeClass" }, | ||
| { name: "SOMEOTHERNAME", class_name: "SomeOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v1" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations"); | ||
| expect(std.out).toMatchInlineSnapshot(` | ||
| " | ||
| ⛅️ wrangler x.x.x | ||
| ────────────────── | ||
| ┌─┬─┬─┬─┐ | ||
| │ New Classes │ New SQLite Classes │ Renamed Classes │ Deleted Classes │ | ||
| ├─┼─┼─┼─┤ | ||
| │ SomeOtherClass │ │ │ │ | ||
| └─┴─┴─┴─┘" | ||
| `); | ||
| }); | ||
|
|
||
| test("it can list multiple pending DO migrations", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMESQLITENAME", class_name: "SomeSQLiteClass" }, | ||
| { name: "THATOTHERNAME", class_name: "ThatOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| { | ||
| tag: "v3", | ||
| new_classes: ["ThisOtherClass"], | ||
| new_sqlite_classes: ["SomeSQLiteClass"], | ||
| }, | ||
| { | ||
| tag: "v4", | ||
| deleted_classes: ["SomeClass", "SomeOtherClass"], | ||
| renamed_classes: [{ from: "ThisOtherClass", to: "ThatOtherClass" }], | ||
| }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v2" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations"); | ||
| expect(std.out).toMatchInlineSnapshot(` | ||
| " | ||
| ⛅️ wrangler x.x.x | ||
| ────────────────── | ||
| ┌─┬─┬─┬─┐ | ||
| │ New Classes │ New SQLite Classes │ Renamed Classes │ Deleted Classes │ | ||
| ├─┼─┼─┼─┤ | ||
| │ ThisOtherClass │ SomeSQLiteClass │ │ │ | ||
| ├─┼─┼─┼─┤ | ||
| │ │ │ ThisOtherClass to ThatOtherClass │ SomeClass │ | ||
| │ │ │ │ SomeOtherClass │ | ||
| └─┴─┴─┴─┘" | ||
| `); | ||
| }); | ||
|
|
||
| test("it can no pending DO migrations", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMESQLITENAME", class_name: "SomeSQLiteClass" }, | ||
| { name: "THATOTHERNAME", class_name: "ThatOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| { | ||
| tag: "v3", | ||
| new_classes: ["ThisOtherClass"], | ||
| new_sqlite_classes: ["SomeSQLiteClass"], | ||
| }, | ||
| { | ||
| tag: "v4", | ||
| deleted_classes: ["SomeClass", "SomeOtherClass"], | ||
| renamed_classes: [{ from: "ThisOtherClass", to: "ThatOtherClass" }], | ||
| }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v4" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations"); | ||
| expect(std.out).toMatchInlineSnapshot(` | ||
| " | ||
| ⛅️ wrangler x.x.x | ||
| ────────────────── | ||
| No DO migrations pending for this worker" | ||
| `); | ||
| }); | ||
|
|
||
| test("it can list a pending DO migration (json)", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMENAME", class_name: "SomeClass" }, | ||
| { name: "SOMEOTHERNAME", class_name: "SomeOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v1" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations --json"); | ||
| expect(std.out).toMatchInlineSnapshot(` | ||
| "[ | ||
| { | ||
| \\"new_classes\\": [ | ||
| \\"SomeOtherClass\\" | ||
| ] | ||
| } | ||
| ]" | ||
| `); | ||
| }); | ||
|
|
||
| test("it can list multiple pending DO migrations (json)", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMESQLITENAME", class_name: "SomeSQLiteClass" }, | ||
| { name: "THATOTHERNAME", class_name: "ThatOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| { | ||
| tag: "v3", | ||
| new_classes: ["ThisOtherClass"], | ||
| new_sqlite_classes: ["SomeSQLiteClass"], | ||
| }, | ||
| { | ||
| tag: "v4", | ||
| deleted_classes: ["SomeClass", "SomeOtherClass"], | ||
| renamed_classes: [{ from: "ThisOtherClass", to: "ThatOtherClass" }], | ||
| }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v2" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations --json"); | ||
| expect(std.out).toMatchInlineSnapshot(` | ||
| "[ | ||
| { | ||
| \\"new_classes\\": [ | ||
| \\"ThisOtherClass\\" | ||
| ], | ||
| \\"new_sqlite_classes\\": [ | ||
| \\"SomeSQLiteClass\\" | ||
| ] | ||
| }, | ||
| { | ||
| \\"deleted_classes\\": [ | ||
| \\"SomeClass\\", | ||
| \\"SomeOtherClass\\" | ||
| ], | ||
| \\"renamed_classes\\": [ | ||
| { | ||
| \\"from\\": \\"ThisOtherClass\\", | ||
| \\"to\\": \\"ThatOtherClass\\" | ||
| } | ||
| ] | ||
| } | ||
| ]" | ||
| `); | ||
| }); | ||
|
|
||
| test("it can no pending DO migrations (json)", async () => { | ||
| writeWranglerConfig({ | ||
| durable_objects: { | ||
| bindings: [ | ||
| { name: "SOMESQLITENAME", class_name: "SomeSQLiteClass" }, | ||
| { name: "THATOTHERNAME", class_name: "ThatOtherClass" }, | ||
| ], | ||
| }, | ||
| migrations: [ | ||
| { tag: "v1", new_classes: ["SomeClass"] }, | ||
| { tag: "v2", new_classes: ["SomeOtherClass"] }, | ||
| { | ||
| tag: "v3", | ||
| new_classes: ["ThisOtherClass"], | ||
| new_sqlite_classes: ["SomeSQLiteClass"], | ||
| }, | ||
| { | ||
| tag: "v4", | ||
| deleted_classes: ["SomeClass", "SomeOtherClass"], | ||
| renamed_classes: [{ from: "ThisOtherClass", to: "ThatOtherClass" }], | ||
| }, | ||
| ], | ||
| }); | ||
| mockLegacyScriptData({ | ||
| scripts: [{ id: "test-name", migration_tag: "v4" }], | ||
| }); | ||
|
|
||
| await runWrangler("check do-migrations --json"); | ||
| expect(std.out).toMatchInlineSnapshot(`"[]"`); | ||
| }); | ||
| }); |
6 changes: 3 additions & 3 deletions
6
packages/wrangler/src/__tests__/friendly-validator-errors.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { createNamespace } from "../core/create-command"; | ||
|
|
||
| export const checkNamespace = createNamespace({ | ||
| metadata: { | ||
| description: "☑︎ Run checks on your Worker", | ||
| owner: "Workers: Authoring and Testing", | ||
| status: "alpha", | ||
| hidden: true, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { createCommand, createNamespace } from "../core/create-command"; | ||
| import { getMigrationsToUpload } from "../durable"; | ||
| import { UserError } from "../errors"; | ||
| import { isNonInteractiveOrCI } from "../is-interactive"; | ||
| import { logger } from "../logger"; | ||
| import { requireAuth } from "../user"; | ||
| import { getScriptName } from "../utils/getScriptName"; | ||
|
|
||
| export const checkNamespace = createNamespace({ | ||
| metadata: { | ||
| description: "🔍 Check pending migrations for your Worker", | ||
| owner: "Workers: Deploy and Config", | ||
| status: "alpha", | ||
| hidden: true, | ||
| }, | ||
| }); | ||
|
|
||
| export const checkDOMigrationCommand = createCommand({ | ||
| args: { | ||
| name: { | ||
| describe: "Name of the Worker", | ||
| type: "string", | ||
| requiresArg: true, | ||
| }, | ||
| json: { | ||
| describe: "Return output as a clean JSON object", | ||
| type: "boolean", | ||
| default: false, | ||
| }, | ||
| }, | ||
| behaviour: { | ||
| printBanner: (args) => !args.json, | ||
| }, | ||
| metadata: { | ||
| description: "🔍 Check pending migrations for your Worker", | ||
| owner: "Workers: Authoring and Testing", | ||
| status: "alpha", | ||
| }, | ||
| handler: async function doMigrationHandler(args, { config }) { | ||
| const accountId = await requireAuth(config); | ||
| const name = getScriptName(args, config); | ||
|
|
||
| if (!name) { | ||
| throw new UserError( | ||
| 'You need to provide a name of your worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`', | ||
| { telemetryMessage: true } | ||
| ); | ||
| } | ||
|
|
||
| const migrations = await getMigrationsToUpload(name, { | ||
| accountId, | ||
| config, | ||
| // deprecated fields | ||
| useServiceEnvironments: undefined, | ||
| env: undefined, | ||
| dispatchNamespace: undefined, | ||
| }); | ||
|
|
||
| if (args.json || isNonInteractiveOrCI()) { | ||
| logger.json(migrations?.steps ?? []); | ||
| return; | ||
| } | ||
|
|
||
| if (!migrations || migrations.steps.length === 0) { | ||
| logger.log("No DO migrations pending for this worker"); | ||
| } else { | ||
| logger.table( | ||
| migrations.steps.map((migration) => { | ||
| const new_classes = migration.new_classes?.join("\n") ?? ""; | ||
| const new_sqlite_classes = | ||
| migration.new_sqlite_classes?.join("\n") ?? ""; | ||
| const renamed_classes = | ||
| migration.renamed_classes | ||
| ?.map((renamed_class) => { | ||
| return `${renamed_class.from} to ${renamed_class.to}`; | ||
| }) | ||
| .join("\n") ?? ""; | ||
| const deleted_classes = migration.deleted_classes?.join("\n") ?? ""; | ||
|
|
||
| return { | ||
| "New Classes": new_classes, | ||
| "New SQLite Classes": new_sqlite_classes, | ||
| "Renamed Classes": renamed_classes, | ||
| "Deleted Classes": deleted_classes, | ||
| }; | ||
| }) | ||
| ); | ||
| } | ||
| }, | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.