Use the new Managed Postgres API in the fly launch command - #5076
Open
miguel-fly wants to merge 1 commit into
Open
Use the new Managed Postgres API in the fly launch command#5076miguel-fly wants to merge 1 commit into
fly launch command#5076miguel-fly wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates fly launch to provision Managed Postgres clusters via the newer Machines/Flaps-served /v1/postgres API by introducing a new internal internal/mpg client, and switches MPG region availability checks to use the Machines regions listing.
Changes:
- Added a new
internal/mpgHTTP client for creating clusters, fetching clusters, and retrieving user credentials. - Updated
fly launchmanaged-Postgres provisioning flow to use the new client and buildDATABASE_URLfrom the cluster pooler endpoint + default user. - Switched MPG region validation to use Machines/Flaps region data (and updated tests accordingly).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/mpg/regions.go | Adds region availability helpers backed by Flaps/Machines regions. |
| internal/mpg/client.go | Introduces the new Managed Postgres API client and models. |
| internal/command/launch/webui.go | Updates web UI plan editing to validate MPG regions via the new helpers. |
| internal/command/launch/plan/postgres.go | Updates default/forced MPG selection logic to use new region validation helpers. |
| internal/command/launch/plan/postgres_test.go | Updates tests to mock region availability via the Flaps regions client. |
| internal/command/launch/launch_databases.go | Switches MPG cluster creation/polling/credentials + DATABASE_URL to the new client. |
| internal/cmdutil/preparers/preparers.go | Ensures the new internal/mpg client is initialized into context. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+178
to
+181
| var env clusterEnvelope | ||
| if err := c.do(ctx, http.MethodGet, "/v1/postgres/"+id, nil, &env, http.StatusOK); err != nil { | ||
| return Cluster{}, err | ||
| } |
| // GetUserCredentials returns the username and current password for a named user. | ||
| func (c *httpClient) GetUserCredentials(ctx context.Context, id, username string) (UserCredentials, error) { | ||
| var env userCredentialsEnvelope | ||
| path := fmt.Sprintf("/v1/postgres/%s/users/%s/credentials", id, username) |
Comment on lines
168
to
172
| var ( | ||
| io = iostreams.FromContext(ctx) | ||
| pgPlan = state.Plan.Postgres.ManagedPostgres | ||
| mpgClient = mpgv1.ClientFromContext(ctx) | ||
| mpgClient = mpgapi.ClientFromContext(ctx) | ||
| ) |
Comment on lines
246
to
248
| // Create a separate context for the wait loop with 15 minute timeout | ||
| waitCtx := context.Background() | ||
| waitCtx, cancel := context.WithTimeout(waitCtx, 15*time.Minute) |
| err = retry.Do( | ||
| func() error { | ||
| cluster, err := mpgClient.GetManagedClusterById(ctx, response.Data.Id) | ||
| current, err := mpgClient.GetCluster(ctx, clusterID) |
Comment on lines
+128
to
+137
| func (c Cluster) ConnectionURI(password string) string { | ||
| u := url.URL{ | ||
| Scheme: "postgres", | ||
| User: url.UserPassword(DefaultUsername, password), | ||
| Host: fmt.Sprintf("%s:%d", c.Endpoints.Primary.Pooler.Host, DefaultPort), | ||
| Path: "/" + DefaultDatabase, | ||
| } | ||
|
|
||
| return u.String() | ||
| } |
Contributor
|
@NullHypothesis ah my bad goat, didnt realize you were already reviewing this one. Didnt mean to step on your toes, would still love your eyes on it |
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.
Change Summary
What and Why:
fly launch still creates managed Postgres clusters through the old v1 API. This moves it to the new /v1/postgres API (served through flaps) with a new internal/mpg client.
This is a first step toward retiring v1 cluster creation in flyctl.
How:
Documentation