mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
56b916a2b0
* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package setup
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
_ "embed"
|
|
|
|
"github.com/caos/logging"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/caos/zitadel/internal/database"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/migration"
|
|
)
|
|
|
|
var (
|
|
//go:embed steps.yaml
|
|
defaultSteps []byte
|
|
)
|
|
|
|
func New() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "setup",
|
|
Short: "setup ZITADEL instance",
|
|
Long: `sets up data to start ZITADEL.
|
|
Requirements:
|
|
- cockroachdb`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
config := new(Config)
|
|
err := viper.Unmarshal(config)
|
|
logging.OnError(err).Fatal("unable to read config")
|
|
|
|
v := viper.New()
|
|
v.SetConfigType("yaml")
|
|
err = v.ReadConfig(bytes.NewBuffer(defaultSteps))
|
|
logging.OnError(err).Fatal("unable to read setup steps")
|
|
|
|
steps := new(Steps)
|
|
err = v.Unmarshal(steps)
|
|
logging.OnError(err).Fatal("unable to read steps")
|
|
|
|
setup(config, steps)
|
|
},
|
|
}
|
|
}
|
|
|
|
func setup(config *Config, steps *Steps) {
|
|
dbClient, err := database.Connect(config.Database)
|
|
logging.OnError(err).Fatal("unable to connect to database")
|
|
|
|
eventstoreClient, err := eventstore.Start(dbClient)
|
|
logging.OnError(err).Fatal("unable to start eventstore")
|
|
|
|
steps.S1ProjectionTable = &ProjectionTable{dbClient: dbClient}
|
|
|
|
migration.Migrate(context.Background(), eventstoreClient, steps.S1ProjectionTable)
|
|
}
|