2023-02-09 21:27:47 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
"codeberg.org/codeberg/pages/server/database"
|
|
|
|
)
|
|
|
|
|
2023-02-09 21:39:37 +01:00
|
|
|
func openCertDB(ctx *cli.Context) (certDB database.CertDB, close func(), err error) {
|
2023-02-09 21:27:47 +01:00
|
|
|
if ctx.String("db-type") != "" {
|
|
|
|
log.Trace().Msg("use xorm mode")
|
|
|
|
certDB, err = database.NewXormDB(ctx.String("db-type"), ctx.String("db-conn"))
|
|
|
|
if err != nil {
|
2023-02-09 21:39:37 +01:00
|
|
|
return nil, nil, fmt.Errorf("could not connect to database: %w", err)
|
2023-02-09 21:27:47 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO: remove in next version
|
|
|
|
fmt.Println(`
|
|
|
|
######################
|
|
|
|
## W A R N I N G !!! #
|
|
|
|
######################
|
|
|
|
|
|
|
|
You use "pogreb" witch is deprecated and will be removed in the next version.
|
|
|
|
Please switch to sqlite, mysql or postgres !!!
|
|
|
|
|
2023-02-09 21:39:37 +01:00
|
|
|
The simplest way is, to use './pages certs migrate' and set environment var DB_TYPE to 'sqlite' on next start.`)
|
2023-02-09 21:27:47 +01:00
|
|
|
log.Error().Msg("depricated \"pogreb\" used\n")
|
|
|
|
|
|
|
|
certDB, err = database.NewPogreb(ctx.String("db-pogreb"))
|
|
|
|
if err != nil {
|
2023-02-09 21:39:37 +01:00
|
|
|
return nil, nil, fmt.Errorf("could not create database: %w", err)
|
2023-02-09 21:27:47 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-09 21:39:37 +01:00
|
|
|
|
|
|
|
close = func() {
|
|
|
|
if err := certDB.Close(); err != nil {
|
|
|
|
log.Error().Err(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return certDB, close, nil
|
2023-02-09 21:27:47 +01:00
|
|
|
}
|