Add embedded PostgreSQL support via --embedded-postgres flag

Co-authored-by: unknwon <2946214+unknwon@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-06 01:29:19 +00:00
parent 39b27c3503
commit 4616bd64dd
4 changed files with 119 additions and 1 deletions

View File

@@ -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)