Skip to content
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

🐛 BUG: Confusing messaging about whether wrangler d1 migrations apply is running against local vs remote DB #7657

Open
robmv opened this issue Jan 2, 2025 · 3 comments
Labels
d1 Relating to D1 enhancement New feature or request

Comments

@robmv
Copy link

robmv commented Jan 2, 2025

Which Cloudflare product(s) does this pertain to?

D1, Workers Runtime

What versions are you using?

3.99.0 Wrangler 2.11.0 Node.js

What operating system and version are you using?

Fedora Linux

Please provide a link to a minimal reproduction

No response

Describe the Bug

I am on first stage development, not a single worker has been deployed, so I have never logged in with wrangler. Running npx wrangler d1 migrations apply DB and it immediately opens the OAuth web page for authentication so it is trying to run the migrations on remote database.

The documentation states that --local is default true but I still need to add it in order to run it on a local database. It is extremely dangerous that the default doesn't match the documentation.

It would be helpful if the local or remote status of the operation to be shows the confirmation message:

Your database may not be available to serve requests during the migration, continue?

The remote or local status of the database is only shown after confirmation:

Executing on local database DB

Please provide any relevant error logs

No response

@robmv robmv added the bug Something that isn't working label Jan 2, 2025
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jan 2, 2025
@irvinebroque irvinebroque added the d1 Relating to D1 label Jan 2, 2025
@emily-shen
Copy link
Contributor

Hiya, I think this is actually a case of confusing UI (not good either!), but the default is local based on my testing + looking through our codebase.

  • you're prompted to login, but this is just to check the DB exists on your account, not to run on a remote version
  • if you don't add --local, it does run against the local DB but doesn't indicate this at the confirm stage, which is concerning for users (especially new ones!)
    Let me know if that doesn't match up with your experience :)

Separately, I'm a bit confused by your description, not sure if I've misunderstood - if you haven't logged in with wrangler, how have you been able to create a d1 database? Currently you have to create a DB linked to an account first before being able to develop locally (this is a limitation we're working to remove!).

@emily-shen emily-shen changed the title 🐛 BUG: Dangerous wrong default for wrangler d1 migrations apply 🐛 BUG: Confusing messaging about whether wrangler d1 migrations apply is running against local vs remote DB Jan 3, 2025
@emily-shen emily-shen added error-messaging Improving user facing error messages awaiting reporter response Needs clarification or followup from OP labels Jan 3, 2025
@robmv
Copy link
Author

robmv commented Jan 3, 2025

  • you're prompted to login, but this is just to check the DB exists on your account, not to run on a remote version

Interesting but when I run with --local, no online db confirmation is done, and as the documentation says --local is the default, doing something different to what --local does looks incongruent.

  • if you don't add --local, it does run against the local DB but doesn't indicate this at the confirm stage, which is concerning for users (especially new ones!)
    Let me know if that doesn't match up with your experience :)

Yes, a message before the confirmation prompt instead of after would be helpful. I expect that wrangler could do all development locally, if my tests makes us expand to more developers, I want all of them to be able code locally without a single Cloudfare login prompt.

Separately, I'm a bit confused by your description, not sure if I've misunderstood - if you haven't logged in with wrangler, how have you been able to create a d1 database? Currently you have to create a DB linked to an account first before being able to develop locally (this is a limitation we're working to remove!).

That restriction looks like is already fixed, because I am not logged in right now, and I tested my first DB migration, my first query and I have:

.wrangler/state/v3/d1/miniflare-D1DatabaseObject/f71b29a609...sqlite

The only setting I added was to wrangler.toml:

[[d1_databases]]
binding = "DB"
database_name = "TODO"
database_id = "TODO"

@emily-shen
Copy link
Contributor

emily-shen commented Jan 3, 2025

That restriction looks like is already fixed, because I am not logged in right now, and I tested my first DB migration, my first query and I have:

Ah yeah fair enough you can definitely just put in a temp id and name currently :)

Re main issue: when --local is not set explicitly, its hitting some code that looks for a remote DB and backs it up. It does thankfully still execute on a local DB by default, and this should be an easy fix for us. Thanks for finding this!

@emily-shen emily-shen removed the error-messaging Improving user facing error messages label Jan 3, 2025
@emily-shen emily-shen moved this from Untriaged to Backlog in workers-sdk Jan 3, 2025
@emily-shen emily-shen removed the awaiting reporter response Needs clarification or followup from OP label Jan 3, 2025
@joshthoward joshthoward added enhancement New feature or request and removed bug Something that isn't working labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d1 Relating to D1 enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

4 participants