Skip to content

fix: Use resolved server directory in migration commands - #4434

Merged
exaby73 merged 8 commits into
mainfrom
copilot/fix-create-migration-issue
Dec 16, 2025
Merged

exaby73 merged 8 commits into
mainfrom
copilot/fix-create-migration-issue

Conversation

Copilot AI commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor
  • Explored the repository structure and identified the issue
  • Analyzed GeneratorConfig.load and ServerDirectoryFinder
  • Identified the root cause in create_migration.dart and create_repair_migration.dart
  • Created comprehensive tests to verify the issue and fix
  • Fixed create_migration.dart to use resolved server directory
  • Fixed create_repair_migration.dart to use resolved server directory
  • Formatted and analyzed code changes
  • All tests pass (new and existing)
  • Manual verification completed from multiple directories
  • Code review passed with no issues
  • CodeQL security check passed
  • Fixed CI formatting and analyzer issues
  • Added tests for create-repair-migration command
  • Refactored to use getProjectName with server directory
  • Restructured tests following Given-When-Then pattern
  • Removed unnecessary comments from tests
  • Refactored to use test_descriptor for temp directory management
Original prompt

This section details on the original issue you should resolve

<issue_title>create-migration does not work from non server directory</issue_title>
<issue_description>### Describe the bug

We recently added support for running serverpod generate from any directory within the project. This change was done in the generator config's load factory. This factory is used by other commands such as the migration set of commands.

In a monorepo project, in the following scenarios where a root pubspec with name: _ may exist (pub workspaces):

  1. [Expected] A project with a single _server directory such as a fresh project from serverpod create

We get the following error outputted:

Not a server package (_). Please make sure your server package name ends with '_server'.
  1. [Bug] A project with multiple _server directories exist, such as a monorepo with the server and custom modules in a workspace configuration

We get the following error outputted:

Multiple Serverpod server projects found. Select one:
(○) /path/to/foo/module/bar/bar_server
(●) /path/to/foo/foo_server

Press [Enter] to confirm.
Not a server package (_). Please make sure your server package name ends with '_server'.

To reproduce

See above description

Expected behavior

We should either:

  1. Immediately fail without trying to resolve the server directory
  2. (Preferred) we should allow all CLI commands to be run from any directory, taking advantage of the interactive server directory prompt

This should also be extended to other commands. All commands using GeneratorConfig.load will have this issue if we aren't using the resolved by GeneratorConfig.load.

Library version

Current main as of posting this issue / version 3.0.1

Platform information

N/A

Additional context

Tests for this should exist in tests/serverpod_cli_e2e_test/test

How experienced are you with this library?

Expert - Experienced and comfortable with using this library in complex projects

Are you interested in working on a PR for this?

  • I want to work on this</issue_description>

Comments on the Issue (you are @copilot in this section)

@SandPod I see that there is something wrong but I don't understand the issue.

Is 1 under Describe the bug expected behavior? It looks like a bug to me.

I would say 2 is working as intended. If we have multiple Serverpod projects that exist and we start the search at a location where we can't unambiguously determine which project is intended, we should prompt the user for feedback.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Modified create_migration.dart to use config.serverPackageDirectoryPathParts
- Modified create_repair_migration.dart to use config.serverPackageDirectoryPathParts
- Replaced getProjectName() calls with config.name
- Removed unused project_name.dart imports
- Added test to verify migration works from different directories

Co-authored-by: exaby73 <[email protected]>
Copilot AI changed the title [WIP] Fix create-migration command not working from non-server directory fix: Use resolved server directory in migration commands Dec 12, 2025
Copilot AI requested a review from exaby73 December 12, 2025 14:04
@exaby73

exaby73 commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

@copilot Analyzer and formatting CI fails

- Removed unused serverDir variables from test groups
- Applied dart format to fix CI formatting check
- All analyzer checks pass

Co-authored-by: exaby73 <[email protected]>

Copilot AI commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor Author

@copilot Analyzer and formatting CI fails

Fixed in commit 080632d. Removed unused variables and applied dart format.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.mixpanel.com
    • Triggering command: /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm --resolved_executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --executable_name=dart /home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/./.dart_tool/pub/bin/serverpod_cli/serverpod_cli.dart-3.10.3.snapshot version (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@exaby73

exaby73 commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

@copilot I do not see tests for repair migration

- Added test for create-repair-migration from project root with name: _
- Added test for create-repair-migration from client directory
- Tests verify commands don't fail with "not a server package" error
- All 4 tests pass (2 for create-migration, 2 for create-repair-migration)

Co-authored-by: exaby73 <[email protected]>

Copilot AI commented Dec 12, 2025 •

Copy link
Copy Markdown
Contributor Author

@copilot I do not see tests for repair migration

Added repair migration tests in commit d804d90. The tests verify that create-repair-migration works from both project root (with name: _ pubspec) and client directory without the "not a server package" error.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.mixpanel.com
    • Triggering command: /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm --resolved_executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --executable_name=dart /home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/./.dart_tool/pub/bin/serverpod_cli/serverpod_cli.dart-3.10.3.snapshot version (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@exaby73 exaby73 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good, few changes on tests and resolving the server project name

- Changed commands to use getProjectName(serverDirectory) to preserve validation
- Moved Process.start calls to setUp blocks following Given-When-Then pattern
- Tests now properly separate "when" (setUp) from "then" (test assertions)
- All 4 tests pass with improved structure

Co-authored-by: exaby73 <[email protected]>

Copilot AI commented Dec 16, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.mixpanel.com
    • Triggering command: /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm --resolved_executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --packages=/home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/.dart_tool/package_config.json file:///home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/.dart_tool/pub/bin/serverpod_cli/serverpod_cli.dart-3.10.3.snapshot version (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from exaby73 December 16, 2025 08:48

@exaby73 exaby73 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just some cleanup required

- Removed "When:" comments from setUp blocks
- Removed assertion comments that duplicate the reason parameter
- Tests remain clear through descriptive test names and reason messages

Co-authored-by: exaby73 <[email protected]>
Copilot AI requested a review from exaby73 December 16, 2025 08:59
@exaby73
exaby73 marked this pull request as ready for review December 16, 2025 09:03
@exaby73
exaby73 requested a review from a team December 16, 2025 09:05

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two minor comments, otherwise the fix looks good! 👍

- Replaced manual tempDir creation/cleanup with test_descriptor's d.sandbox
- Added test_descriptor import (package already in pubspec.yaml)
- All tempDir.path references replaced with d.sandbox
- Simplifies test setup and ensures proper cleanup

Co-authored-by: exaby73 <[email protected]>

Copilot AI commented Dec 16, 2025

Copy link
Copy Markdown
Contributor Author

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.mixpanel.com
    • Triggering command: /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm /opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dartvm --resolved_executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --executable_name=/opt/hostedtoolcache/flutter/stable-3.38.4-x64/bin/cache/dart-sdk/bin/dart --packages=/home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/.dart_tool/package_config.json file:///home/REDACTED/work/serverpod/serverpod/tools/serverpod_cli/.dart_tool/pub/bin/serverpod_cli/serverpod_cli.dart-3.10.3.snapshot version (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@exaby73
exaby73 merged commit 2aee890 into main Dec 16, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 16, 2025
@marcelomendoncasoares
marcelomendoncasoares deleted the copilot/fix-create-migration-issue branch April 8, 2026 15:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-migration does not work from non server directory

3 participants