Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from DataDog/jlegrone/pre-create-namespaces
Browse files Browse the repository at this point in the history
Add CLI flag to pre-create namespaces
  • Loading branch information
jlegrone committed Sep 17, 2021
2 parents 4b74777 + 7803589 commit 7986b5b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ Use the help flag to see all available options:
temporalite start -h
```

### Namespace Registration

Namespaces can be pre-registered at startup so they're available to use right away:
```bash
temporalite start --namespace foo --namespace bar
```

Registering namespaces the old-fashioned way via `tctl --namespace foo namespace register` works too!

### Persistence Modes

#### File on Disk
Expand Down
9 changes: 9 additions & 0 deletions cmd/temporalite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
dbPathFlag = "filename"
portFlag = "port"
logFormatFlag = "log-format"
namespaceFlag = "namespace"
)

func init() {
Expand Down Expand Up @@ -76,6 +77,13 @@ func buildCLI() *cli.App {
EnvVars: nil,
Value: "json",
},
&cli.StringSliceFlag{
Name: namespaceFlag,
Aliases: []string{"n"},
Usage: `specify namespaces that should be pre-created`,
EnvVars: nil,
Value: nil,
},
},
Before: func(c *cli.Context) error {
if c.Args().Len() > 0 {
Expand All @@ -95,6 +103,7 @@ func buildCLI() *cli.App {
opts := []temporalite.ServerOption{
temporalite.WithFrontendPort(c.Int(portFlag)),
temporalite.WithDatabaseFilePath(c.String(dbPathFlag)),
temporalite.WithNamespaces(c.StringSlice(namespaceFlag)...),
}
if c.Bool(ephemeralFlag) {
opts = append(opts, temporalite.WithPersistenceDisabled())
Expand Down
10 changes: 6 additions & 4 deletions internal/common/persistence/sql/sqlplugin/sqlite/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ func (p *plugin) CreateDB(
p.mainDB = newDB(dbKind, cfg.DatabaseName, conn, nil)

// Ensure namespaces exist
namespaces := strings.Split(cfg.ConnectAttributes["preCreateNamespaces"], ",")
for _, ns := range namespaces {
if err := createNamespaceIfNotExists(p.mainDB, ns); err != nil {
return nil, fmt.Errorf("error ensuring namespace exists: %w", err)
if nsConfig := cfg.ConnectAttributes["preCreateNamespaces"]; nsConfig != "" {
namespaces := strings.Split(cfg.ConnectAttributes["preCreateNamespaces"], ",")
for _, ns := range namespaces {
if err := createNamespaceIfNotExists(p.mainDB, ns); err != nil {
return nil, fmt.Errorf("error ensuring namespace exists: %w", err)
}
}
}
}
Expand Down

0 comments on commit 7986b5b

Please sign in to comment.