This commit is contained in:
adlerhurst
2025-02-17 07:55:00 +01:00
parent b85460152c
commit 77ab8226a5
14 changed files with 676 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package configure
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zitadel/zitadel/backend/storage/database/dialect"
)
var (
// ConfigureCmd represents the config command
ConfigureCmd = &cobra.Command{
Use: "configure",
Short: "Guides you through configuring Zitadel",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:
// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("config called")
fmt.Println(viper.AllSettings())
fmt.Println(viper.Sub("database").AllSettings())
pool, err := config.Database.Connect(cmd.Context())
_, _ = pool, err
},
PreRun: ReadConfigPreRun[Config](viper.GetViper(), &config),
}
config Config
)
func init() {
// Here you will define your flags and configuration settings.
ConfigureCmd.Flags().BoolVarP(&config.upgrade, "upgrade", "u", false, "Only changed configuration values since the previously used version will be asked for")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// configureCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
}
type Config struct {
Database dialect.Config
upgrade bool
}
func (c Config) Hooks() []viper.DecoderConfigOption {
return c.Database.Hooks()
}

View File

@@ -0,0 +1,26 @@
package configure
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
type Unmarshaller interface {
Hooks() []viper.DecoderConfigOption
}
func ReadConfigPreRun[C Unmarshaller](v *viper.Viper, config *C) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if err := v.Unmarshal(config, (*config).Hooks()...); err != nil {
panic(err)
}
}
}
func ReadConfig[C Unmarshaller](v *viper.Viper) (*C, error) {
var config C
if err := v.Unmarshal(&config, config.Hooks()...); err != nil {
return nil, err
}
return &config, nil
}

View File

@@ -0,0 +1,23 @@
package prepare
import (
"context"
"github.com/zitadel/zitadel/backend/storage/database"
"github.com/zitadel/zitadel/backend/storage/eventstore"
)
type Step001 struct {
Database database.Pool
}
func (v *Step001) Migrate(ctx context.Context) error {
conn, err := v.Database.Acquire(ctx)
if err != nil {
return err
}
defer conn.Release(ctx)
eventstore.New(conn).
return nil
}

View File

@@ -0,0 +1,15 @@
package start
import (
"github.com/spf13/viper"
"github.com/zitadel/zitadel/backend/storage/database/dialect"
)
type Config struct {
Database dialect.Config
}
func (c Config) Hooks() []viper.DecoderConfigOption {
return c.Database.Hooks()
}