fix(cli): handle AlreadyExists errors in directory creation#5724
Merged
Conversation
`db schema declarative sync` (and `db diff`/`db pull`) aborted with `AlreadyExists: FileSystem.makeDirectory (...\supabase\migrations)` when the migrations directory already existed. Go's `os.MkdirAll` returns nil for an existing directory, but Effect's Bun `FileSystem.makeDirectory` can surface an `AlreadyExists` SystemError even with `recursive: true` on some platforms (notably Windows / OneDrive reparse-point dirs), which regressed the command when it was ported to native TypeScript. Add a shared `legacyMakeDir` helper that recovers from the `AlreadyExists` reason so re-creating an existing directory is a no-op, matching `os.MkdirAll`, and route the migration/output writers in sync, diff, and pull through it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AWa8Hr8BS2pZucac9r3wb7
Supabase CLI previewnpx --yes https://pkg.pr.new/supabase/cli/supabase@9f6a89b36a319ec7a2fc257a485be4a17533e424Preview package for commit |
jgoux
approved these changes
Jun 29, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Extract directory creation logic into a new
legacyMakeDirutility that matches Go'sos.MkdirAllbehavior by treating an already-existing directory as success.The Effect/Bun
FileSystem.makeDirectoryAPI can surface anAlreadyExistsSystemErrorfor existing directories on some platforms (notably Windows with OneDrive reparse points — CLI-1849), even withrecursive: true. This differs from Go'sos.MkdirAll, which returns nil when the target is already a directory.Key changes:
legacyMakeDirutility inapps/cli/src/legacy/shared/legacy-make-dir.tsthat wrapsFileSystem.makeDirectoryand recovers fromAlreadyExistserrorsAlreadyExistsrecovery, and error propagationmakeDirectorycalls indb diff,db pull, anddb schema declarative synchandlers withlegacyMakeDirThis ensures the CLI's migration writers never fail on a pre-existing
supabase/migrationsdirectory, matching the original Go implementation's behavior.https://claude.ai/code/session_01AWa8Hr8BS2pZucac9r3wb7