2023-02-15 01:52:11 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
2023-02-15 03:21:58 +00:00
|
|
|
"embed"
|
2023-02-15 01:52:11 +00:00
|
|
|
"strings"
|
2024-01-25 16:28:20 +00:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-02-15 01:52:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed 07/logstore.sql
|
|
|
|
createLogstoreSchema07 string
|
2023-02-15 03:21:58 +00:00
|
|
|
//go:embed 07/cockroach/access.sql
|
|
|
|
//go:embed 07/postgres/access.sql
|
|
|
|
createAccessLogsTable07 embed.FS
|
|
|
|
//go:embed 07/cockroach/execution.sql
|
|
|
|
//go:embed 07/postgres/execution.sql
|
|
|
|
createExecutionLogsTable07 embed.FS
|
2023-02-15 01:52:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type LogstoreTables struct {
|
|
|
|
dbClient *sql.DB
|
|
|
|
username string
|
2023-02-15 03:21:58 +00:00
|
|
|
dbType string
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 16:28:20 +00:00
|
|
|
func (mig *LogstoreTables) Execute(ctx context.Context, _ eventstore.Event) error {
|
2023-02-15 03:21:58 +00:00
|
|
|
accessStmt, err := readStmt(createAccessLogsTable07, "07", mig.dbType, "access.sql")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
executionStmt, err := readStmt(createExecutionLogsTable07, "07", mig.dbType, "execution.sql")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
stmt := strings.ReplaceAll(createLogstoreSchema07, "%[1]s", mig.username) + accessStmt + executionStmt
|
|
|
|
_, err = mig.dbClient.ExecContext(ctx, stmt)
|
2023-02-15 01:52:11 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mig *LogstoreTables) String() string {
|
|
|
|
return "07_logstore"
|
|
|
|
}
|