mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 18:55:11 +00:00
fix(init): prepare database (#3191)
* fix(init): prepare database * fix(defaults): cockroach local defaults
This commit is contained in:
@@ -2,21 +2,53 @@ package initialise
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
//sql import
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
var (
|
||||
conn string
|
||||
)
|
||||
|
||||
func New() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "initialize ZITADEL instance",
|
||||
Long: `init sets up the minimum requirements to start ZITADEL.
|
||||
Prereqesits:
|
||||
- cockroachdb`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logging.New().Info("hello world")
|
||||
return nil
|
||||
config := new(Config)
|
||||
if err := viper.Unmarshal(config); err != nil {
|
||||
return err
|
||||
}
|
||||
return initialise(config)
|
||||
},
|
||||
}
|
||||
|
||||
// cmd.PersistentFlags().StringArrayVar(&configFiles, "config", nil, "path to config file to overwrite system defaults")
|
||||
//TODO(hust): simplify to multiple flags
|
||||
cmd.PersistentFlags().StringVar(&conn, "connection", "", "connection string to connect with a user which is allowed to create the database and user")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func initialise(config *Config) error {
|
||||
logging.Info("initialization started")
|
||||
|
||||
if conn == "" {
|
||||
return fmt.Errorf("connection not defined")
|
||||
}
|
||||
|
||||
if err := prepareDB(config.Database); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return prepareZitadel(config.Database)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user