Skip to content

Conversation

@nora-soderlund
Copy link
Contributor

@nora-soderlund nora-soderlund commented Mar 6, 2024

What this PR solves / how to test

Previously, if you wanted to remove a migration (e.g. number 5 out of 10), you had to:

  • Comment everything in the migration file and add SELECT ... just to have a query in it; or
  • Delete it and lower the number of all preceding migrations.

Previously:

// 0001_my-cool-migration.sql
// 0003_my-cool-migration.sql

wrangler d1 migrations create my-cool-database my-cool-migration // 0003_my-cool-migration.sql

After:

// 0001_my-cool-migration.sql
// 0003_my-cool-migration.sql

wrangler d1 migrations create my-cool-database my-cool-migration // 0004_my-cool-migration.sql

Author has addressed the following

This PR changes the logic of getNextMigrationNumber to actually get the highest migration number plus one, rather than the first missing migration number plus one, which can be an existing migration number.

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because: no existing test cases for the migration helpers
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because: nothing is explicitly stated about the next migration number in the docs

@nora-soderlund nora-soderlund requested review from a team as code owners March 6, 2024 19:46
@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2024

🦋 Changeset detected

Latest commit: c0d21ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

const migrationNumbers = getMigrationNames(migrationsPath).map((migration) =>
parseInt(migration.split("_")[0])
);
const highestMigrationNumber = Math.max(...migrationNumbers, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explicitly makes the first number 0 + 1, which is a regression to how it works currently where the first number is 0.

If regression is unwanted, putting it to -1 will make it -1 + 1 = 0.

Suggested change
const highestMigrationNumber = Math.max(...migrationNumbers, 0);
const highestMigrationNumber = Math.max(...migrationNumbers, -1);

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-wrangler-5184

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5184/npm-package-wrangler-5184

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-wrangler-5184 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-create-cloudflare-5184 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-cloudflare-kv-asset-handler-5184
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-miniflare-5184
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-cloudflare-pages-shared-5184
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8177849191/npm-package-cloudflare-vitest-pool-workers-5184

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.31.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240223.1
workerd 1.20240304.0 1.20240304.0
workerd --version 1.20240304.0 2024-03-04

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@codecov
Copy link

codecov bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.38%. Comparing base (2713977) to head (c0d21ec).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5184      +/-   ##
==========================================
+ Coverage   70.35%   70.38%   +0.03%     
==========================================
  Files         298      298              
  Lines       15567    15565       -2     
  Branches     4007     4006       -1     
==========================================
+ Hits        10952    10956       +4     
+ Misses       4615     4609       -6     
Files Coverage Δ
packages/wrangler/src/d1/migrations/helpers.ts 94.54% <100.00%> (-0.20%) ⬇️

... and 6 files with indirect coverage changes

@rozenmd
Copy link
Contributor

rozenmd commented Mar 7, 2024

Just holding off merging this until #4930 is in

@rozenmd rozenmd merged commit 046930e into cloudflare:main Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants