-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add postgres setup and migration to ftl serve
#518
Conversation
274ca66
to
b959593
Compare
cmd/ftl/cmd_serve.go
Outdated
select { | ||
case <-pollCtx.Done(): | ||
return errors.New("timed out waiting for container to be healthy") | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use case <-time.After(100 * time.Millisecond):
instead of this and the sleep below.
LGTM nice! |
dc7e49e
to
1de7367
Compare
cmd/ftl/cmd_serve.go
Outdated
func setupDB(ctx context.Context) (*string, error) { | ||
logger := log.FromContext(ctx) | ||
|
||
dsn := fmt.Sprintf("postgres://postgres:secret@localhost:5433/%s?sslmode=disable", ftlDBName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a better idea to dynamically allocate the port, then retrieve it, rather than hard-coding it. Either that, or add a flag for controlling it.
cmd/ftl/cmd_serve.go
Outdated
"--user", "postgres", | ||
"--restart", "always", | ||
"-e", "POSTGRES_PASSWORD=secret", | ||
"-p", "5433:5432", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re. the above comment, changing this to -p 5432
will dynamically allocate a port. I think you could then pull the real port out of the docker inspect
below.
cmd/ftl/cmd_serve.go
Outdated
@@ -105,6 +118,66 @@ func (s *serveCmd) Run(ctx context.Context) error { | |||
return nil | |||
} | |||
|
|||
func setupDB(ctx context.Context) (*string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a pointer to a string, just return a string.
fd34cf6
to
bdf6d28
Compare
@alecthomas added some updates. Is this closer to what you were thinking? Thanks for the suggestions!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naisu!
return "", errors.WithStack(err) | ||
} | ||
|
||
dsn := fmt.Sprintf("postgres://postgres:secret@localhost:%s/%s?sslmode=disable", strings.TrimSpace(string(port)), ftlContainerName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Fixes #499
When docker isn't running
When the database hasn't been created yet
When the database already exists
ftl serve info: Checking for FTL database info: Starting 1 controller(s) and 10 runner(s)