mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
4272ea6fe1
* fix(init): add sub commands * fix(init): admin user in config, test(init): verify functions * refactor: config, remove second commands * refactor: init steps * chore: fix link in readme * chore: numerate sql files * Update cmd/admin/initialise/sql/README.md Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update cmd/admin/initialise/sql/README.md Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix(init): remove unused index * user * fix database username in defaults.yaml Co-authored-by: Livio Amstutz <livio.a@gmail.com>
29 lines
649 B
Go
29 lines
649 B
Go
package initialise
|
|
|
|
import (
|
|
"database/sql"
|
|
)
|
|
|
|
func exists(query string, args ...interface{}) func(*sql.DB) (exists bool, err error) {
|
|
return func(db *sql.DB) (exists bool, err error) {
|
|
row := db.QueryRow("SELECT EXISTS("+query+")", args...)
|
|
err = row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
}
|
|
|
|
func exec(stmt string, args ...interface{}) func(*sql.DB) error {
|
|
return func(db *sql.DB) error {
|
|
_, err := db.Exec(stmt, args...)
|
|
return err
|
|
}
|
|
}
|
|
|
|
func verify(db *sql.DB, checkExists func(*sql.DB) (bool, error), create func(*sql.DB) error) error {
|
|
exists, err := checkExists(db)
|
|
if exists || err != nil {
|
|
return err
|
|
}
|
|
return create(db)
|
|
}
|