mirror of
https://github.com/gogs/gogs.git
synced 2026-05-07 01:07:15 +02:00
Add embedded PostgreSQL support via --embedded-postgres flag
Co-authored-by: unknwon <2946214+unknwon@users.noreply.github.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"gogs.io/gogs/internal/conf"
|
||||
"gogs.io/gogs/internal/context"
|
||||
"gogs.io/gogs/internal/database"
|
||||
"gogs.io/gogs/internal/embeddedpg"
|
||||
"gogs.io/gogs/internal/form"
|
||||
"gogs.io/gogs/internal/osutil"
|
||||
"gogs.io/gogs/internal/route"
|
||||
@@ -54,6 +55,7 @@ and it takes care of all the other things for you`,
|
||||
Flags: []cli.Flag{
|
||||
stringFlag("port, p", "3000", "Temporary port number to prevent conflict"),
|
||||
stringFlag("config, c", "", "Custom configuration file path"),
|
||||
boolFlag("embedded-postgres", "Use embedded PostgreSQL database"),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -160,6 +162,21 @@ func newMacaron() *macaron.Macaron {
|
||||
}
|
||||
|
||||
func runWeb(c *cli.Context) error {
|
||||
var localPg *embeddedpg.LocalPostgres
|
||||
|
||||
if c.Bool("embedded-postgres") {
|
||||
localPg = embeddedpg.Initialize(conf.WorkDir())
|
||||
if err := localPg.Launch(); err != nil {
|
||||
log.Fatal("Failed to launch embedded postgres: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := localPg.Shutdown(); err != nil {
|
||||
log.Error("Failed to shutdown embedded postgres: %v", err)
|
||||
}
|
||||
}()
|
||||
localPg.ConfigureGlobalDatabase()
|
||||
}
|
||||
|
||||
err := route.GlobalInit(c.String("config"))
|
||||
if err != nil {
|
||||
log.Fatal("Failed to initialize application: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user