Fix #30: server.region matches the chosen cloud provider#35
Merged
Conversation
The servers.region column had a Hetzner-centric migration default
('nbg1'), and the three Server::create() call sites all omitted region
from the insert payload. So a team created on DigitalOcean ended up
with server.region='nbg1' even though the droplet was actually
created in 'nyc1' (the DO job hardcoded its own region from config
'cloud.regions.us-east.digitalocean').
This was mostly cosmetic — the DO API ignores our column — but it
masked the wrong provider in observability and would have broken any
future region-aware code reading server.region.
Fix:
- New CloudProvider::defaultProviderRegion() returns the provider-
specific code ('nyc1', 'ash', 'us-east', 'local') from the
cloud.regions.us-east.<provider> config, with hardcoded fallbacks
for safety.
- TeamController::provisionServer, AgentController::ensureTeamHasServer,
and FixServerStatus::handle now set 'region' on the Server row using
the helper. Three sites, one source of truth.
Tests: 7 new tests covering each provider's default code, the config-
absent fallback path, and end-to-end team creation asserting
server.region matches the chosen provider. Full suite: 686 passed,
106 skipped.
Fixes #30
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.
Summary
The
servers.regioncolumn had a Hetzner-centric migration default ('nbg1'), and the three call sites that insert Server rows all omittedregionfrom the create payload. A team provisioned on DigitalOcean therefore ended up withserver.region='nbg1'even though the droplet was actually created in'nyc1'(the DO job hardcodes its own region fromconfig('cloud.regions.us-east.digitalocean')).Mostly cosmetic — the DO API ignores our column — but it misrepresented the actual provider in dashboards / Telescope / observability, and any future code that reads
server.regionto call provider APIs would break.Fixes #30.
Changes
app/Enums/CloudProvider.php: newdefaultProviderRegion()that returns the provider-specific code:DigitalOcean→'nyc1'Hetzner→'ash'Linode→'us-east'Docker→'local'Reads from
cloud.regions.us-east.<provider>config first (so any deploy-level region remap works), falls back to hardcoded per-provider defaults if config is missing.app/Http/Controllers/Settings/TeamController::provisionServer: setregionfrom$cloudProvider->defaultProviderRegion()when creating the Server row.app/Http/Controllers/AgentController::ensureTeamHasServer: same.app/Console/Commands/FixServerStatus::handle: same.Three sites, one source of truth.
Tests
7 new tests across two files:
tests/Feature/Enums/CloudProviderTest.php(5): each provider's default code, plus the config-absent fallback path.tests/Feature/Teams/TeamCreationProvisioningTest.php(2): end-to-end team creation through the actual controller — assertingserver.regionmatches the chosen provider for both DO and Hetzner.Full suite:
Pint: clean.
Out of scope
The migration default
'nbg1'is still in the schema. Changing it would require a migration on existing data and isn't necessary now that all create sites set the column explicitly. If the cosmetic schema default bothers you, a follow-up can change the default to'local'or drop it.Live E2E status
php artisan tinker --execute='echo App\Models\Server::latest()->first()->region;'→ expectnyc1ashTest plan
server.regionmatches the provider for each cloud