mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-10 23:52:16 +00:00
feat: projections auto create their tables (#3324)
* 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
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
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 {
|
||||
@@ -14,9 +26,33 @@ func New() *cobra.Command {
|
||||
Long: `sets up data to start ZITADEL.
|
||||
Requirements:
|
||||
- cockroachdb`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logging.Info("hello world")
|
||||
return nil
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user