Skip to content

Commit

Permalink
feat: always --recreate in dev mode (#3434)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Nov 20, 2024
1 parent 4a40b63 commit 89146a3
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .goosehints
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NOTE: ftl dev command will run things as a server so you will need to run it as

### Development Mode
```bash
ftl dev --recreate ./examples/go
ftl dev ./examples/go
```

### With OpenTelemetry
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Once the Hermit environment is activated you can type the following to start a
hot-reloading ftl agent:

```
$ ftl dev --recreate ./examples/go
$ ftl dev ./examples/go
```

## Development processes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ftl new go . alice
Start FTL in one terminal:

```sh file=test.sh region=start
ftl dev --wait-for=alice --recreate .
ftl dev --wait-for=alice .
```

Then in a second terminal run the following:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/docs/help/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ info: Starting FTL with 1 controller(s)
ftl: error: ERROR: relation "fsm_executions" does not exist (SQLSTATE 42P01)
```

Run again with `ftl dev --recreate`. This usually indicates that your DB has an old schema.
Run again with `ftl dev`. This usually indicates that your DB has an old schema.

This can occur when FTL has been upgraded with schema changes, making the database out of date. While in alpha we do not use schema migrations, so this won't occur once we hit a stable release.
2 changes: 1 addition & 1 deletion examples/online-boutique/Justfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Start the FTL backend with hot-reloading
dev:
ftl dev --recreate --allow-origins '*'
ftl dev --allow-origins '*'

gen-mobile:
ftl schema generate mobile/templates/ online-boutique/mobile/lib/api --watch=5s
Expand Down
16 changes: 8 additions & 8 deletions frontend/cli/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
)

type devCmd struct {
Watch time.Duration `help:"Watch template directory at this frequency and regenerate on change." default:"500ms"`
NoServe bool `help:"Do not start the FTL server." default:"false"`
Lsp bool `help:"Run the language server." default:"false"`
ServeCmd serveCmd `embed:""`
InitDB bool `help:"Initialize the database and exit." default:"false"`
Watch time.Duration `help:"Watch template directory at this frequency and regenerate on change." default:"500ms"`
NoServe bool `help:"Do not start the FTL server." default:"false"`
Lsp bool `help:"Run the language server." default:"false"`
ServeCmd serveCommonConfig `embed:""`
InitDB bool `help:"Initialize the database and exit." default:"false"`
languageServer *lsp.Server
Build buildCmd `embed:""`
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func (d *devCmd) Run(
}

if d.InitDB {
dsn, err := dev.SetupDB(ctx, d.ServeCmd.DatabaseImage, d.ServeCmd.DBPort, d.ServeCmd.Recreate)
dsn, err := dev.SetupDB(ctx, d.ServeCmd.DatabaseImage, d.ServeCmd.DBPort, true)
if err != nil {
return fmt.Errorf("failed to setup database: %w", err)
}
Expand All @@ -87,15 +87,15 @@ func (d *devCmd) Run(
controllerReady := make(chan bool, 1)
if !d.NoServe {
if d.ServeCmd.Stop {
_, err := kctx.Call(d.ServeCmd.Run)
err := d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaClient, true)
if err != nil {
return fmt.Errorf("failed to stop server: %w", err)
}
d.ServeCmd.Stop = false
}

g.Go(func() error {
return d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaClient)
return d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaClient, true)
})
}

Expand Down
13 changes: 9 additions & 4 deletions frontend/cli/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ import (
)

type serveCmd struct {
Recreate bool `help:"Recreate the database even if it already exists." default:"false"`
serveCommonConfig
}

type serveCommonConfig struct {
Bind *url.URL `help:"Starting endpoint to bind to and advertise to. Each controller, ingress, runner and language plugin will increment the port by 1" default:"http://127.0.0.1:8891"`
DBPort int `help:"Port to use for the database." default:"15432"`
RegistryPort int `help:"Port to use for the registry." default:"15000"`
Recreate bool `help:"Recreate the database even if it already exists." default:"false"`
Controllers int `short:"c" help:"Number of controllers to start." default:"1"`
Provisioners int `short:"p" help:"Number of provisioners to start." default:"0" hidden:"true"`
Background bool `help:"Run in the background." default:"false"`
Expand Down Expand Up @@ -72,11 +76,11 @@ func (s *serveCmd) Run(
if err != nil {
return fmt.Errorf("could not create bind allocator: %w", err)
}
return s.run(ctx, projConfig, cm, sm, optional.None[chan bool](), false, bindAllocator, controllerClient, provisionerClient, schemaClient)
return s.run(ctx, projConfig, cm, sm, optional.None[chan bool](), false, bindAllocator, controllerClient, provisionerClient, schemaClient, s.Recreate)
}

//nolint:maintidx
func (s *serveCmd) run(
func (s *serveCommonConfig) run(
ctx context.Context,
projConfig projectconfig.Config,
cm *manager.Manager[configuration.Configuration],
Expand All @@ -87,6 +91,7 @@ func (s *serveCmd) run(
controllerClient ftlv1connect.ControllerServiceClient,
provisionerClient provisionerconnect.ProvisionerServiceClient,
schemaClient ftlv1connect.SchemaServiceClient,
recreate bool,
) error {
logger := log.FromContext(ctx)

Expand Down Expand Up @@ -146,7 +151,7 @@ func (s *serveCmd) run(
registry.AllowInsecure = true
registry.Registry = fmt.Sprintf("127.0.0.1:%d/ftl", s.RegistryPort)
// Bring up the DB and DAL.
dsn, err := dev.SetupDB(ctx, s.DatabaseImage, s.DBPort, s.Recreate)
dsn, err := dev.SetupDB(ctx, s.DatabaseImage, s.DBPort, recreate)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/console/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const config: PlaywrightTestConfig = {
},
],
webServer: {
command: process.env.CI ? 'ftl dev --recreate -j1' : 'ftl dev --recreate',
command: process.env.CI ? 'ftl dev -j1' : 'ftl dev',
url: 'http://localhost:8892',
reuseExistingServer: !process.env.CI,
/* If the test ends up needing to pull the postgres docker image, this can take a while. Give it a few minutes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppSettings : PersistentStateComponent<AppSettings.State> {

data class State(
@NonNls var lspServerPath: String = "ftl",
var lspServerArguments: String = "--recreate --lsp",
var lspServerArguments: String = "--lsp",
var lspServerStopArguments: String = "serve --stop",
var autoRestartLspServer: Boolean = false,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FTLSettingsConfigurable : Configurable {
override fun apply() {
val state = AppSettings.getInstance().state
state.lspServerPath = mySettingsComponent?.getLspServerPath() ?: "ftl"
state.lspServerArguments = mySettingsComponent?.getLspServerArguments() ?: " dev --recreate --lsp"
state.lspServerArguments = mySettingsComponent?.getLspServerArguments() ?: " dev --lsp"
state.lspServerStopArguments = mySettingsComponent?.getLspServerStopArguments() ?: "serve --stop"
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Configure the FTL extension by setting the following options in your Visual Stud
}
```

- `ftl.devCommandFlags`: Defines flags to pass to the FTL executable when starting the development environment. The default is ["--recreate"].
- `ftl.devCommandFlags`: Defines flags to pass to the FTL executable when starting the development environment.

```json
{
"ftl.devCommandFlags": ["--recreate", "--parallelism=4"]
"ftl.devCommandFlags": ["--parallelism=4"]
}
```

Expand Down
4 changes: 1 addition & 3 deletions frontend/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
},
"ftl.devCommandFlags": {
"type": "array",
"default": [
"--recreate"
],
"default": [],
"items": {
"type": "string"
},
Expand Down

0 comments on commit 89146a3

Please sign in to comment.