mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-03 16:22:40 +00:00
Sqlite journal mode (#54)
This commit is contained in:
parent
b2a56fe5a0
commit
3366cde385
6 changed files with 36 additions and 2 deletions
|
@ -109,6 +109,7 @@ You would only need to specify the configuration options you want to change —
|
||||||
| external-url | OG_EXTERNAL_URL | none | Public URL for the Git HTTP/SSH connection. If not set, uses the URL from the request. |
|
| external-url | OG_EXTERNAL_URL | none | Public URL for the Git HTTP/SSH connection. If not set, uses the URL from the request. |
|
||||||
| opengist-home | OG_OPENGIST_HOME | home directory | Path to the directory where Opengist stores its data. |
|
| opengist-home | OG_OPENGIST_HOME | home directory | Path to the directory where Opengist stores its data. |
|
||||||
| db-filename | OG_DB_FILENAME | `opengist.db` | Name of the SQLite database file. |
|
| db-filename | OG_DB_FILENAME | `opengist.db` | Name of the SQLite database file. |
|
||||||
|
| sqlite.journal-mode | OG_SQLITE_JOURNAL_MODE | `WAL` | Set the journal mode for SQLite. More info [here](https://www.sqlite.org/pragma.html#pragma_journal_mode) |
|
||||||
| http.host | OG_HTTP_HOST | `0.0.0.0` | The host on which the HTTP server should bind. |
|
| http.host | OG_HTTP_HOST | `0.0.0.0` | The host on which the HTTP server should bind. |
|
||||||
| http.port | OG_HTTP_PORT | `6157` | The port on which the HTTP server should listen. |
|
| http.port | OG_HTTP_PORT | `6157` | The port on which the HTTP server should listen. |
|
||||||
| http.git-enabled | OG_HTTP_GIT_ENABLED | `true` | Enable or disable git operations (clone, pull, push) via HTTP. (`true` or `false`) |
|
| http.git-enabled | OG_HTTP_GIT_ENABLED | `true` | Enable or disable git operations (clone, pull, push) via HTTP. (`true` or `false`) |
|
||||||
|
|
|
@ -11,6 +11,10 @@ opengist-home:
|
||||||
# Name of the SQLite database file. Default: opengist.db
|
# Name of the SQLite database file. Default: opengist.db
|
||||||
db-filename: opengist.db
|
db-filename: opengist.db
|
||||||
|
|
||||||
|
# Set the journal mode for SQLite. Default: WAL
|
||||||
|
# See https://www.sqlite.org/pragma.html#pragma_journal_mode
|
||||||
|
sqlite.journal-mode: WAL
|
||||||
|
|
||||||
|
|
||||||
# HTTP server configuration
|
# HTTP server configuration
|
||||||
# Host to bind to. Default: 0.0.0.0
|
# Host to bind to. Default: 0.0.0.0
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/thomiceli/opengist/internal/utils"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -24,6 +25,8 @@ type config struct {
|
||||||
OpengistHome string `yaml:"opengist-home" env:"OG_OPENGIST_HOME"`
|
OpengistHome string `yaml:"opengist-home" env:"OG_OPENGIST_HOME"`
|
||||||
DBFilename string `yaml:"db-filename" env:"OG_DB_FILENAME"`
|
DBFilename string `yaml:"db-filename" env:"OG_DB_FILENAME"`
|
||||||
|
|
||||||
|
SqliteJournalMode string `yaml:"sqlite.journal-mode" env:"OG_SQLITE_JOURNAL_MODE"`
|
||||||
|
|
||||||
HttpHost string `yaml:"http.host" env:"OG_HTTP_HOST"`
|
HttpHost string `yaml:"http.host" env:"OG_HTTP_HOST"`
|
||||||
HttpPort string `yaml:"http.port" env:"OG_HTTP_PORT"`
|
HttpPort string `yaml:"http.port" env:"OG_HTTP_PORT"`
|
||||||
HttpGit bool `yaml:"http.git-enabled" env:"OG_HTTP_GIT_ENABLED"`
|
HttpGit bool `yaml:"http.git-enabled" env:"OG_HTTP_GIT_ENABLED"`
|
||||||
|
@ -56,6 +59,8 @@ func configWithDefaults() (*config, error) {
|
||||||
c.OpengistHome = filepath.Join(homeDir, ".opengist")
|
c.OpengistHome = filepath.Join(homeDir, ".opengist")
|
||||||
c.DBFilename = "opengist.db"
|
c.DBFilename = "opengist.db"
|
||||||
|
|
||||||
|
c.SqliteJournalMode = "WAL"
|
||||||
|
|
||||||
c.HttpHost = "0.0.0.0"
|
c.HttpHost = "0.0.0.0"
|
||||||
c.HttpPort = "6157"
|
c.HttpPort = "6157"
|
||||||
c.HttpGit = true
|
c.HttpGit = true
|
||||||
|
@ -108,6 +113,10 @@ func InitLog() {
|
||||||
|
|
||||||
multi := zerolog.MultiLevelWriter(zerolog.NewConsoleWriter(), file)
|
multi := zerolog.MultiLevelWriter(zerolog.NewConsoleWriter(), file)
|
||||||
log.Logger = zerolog.New(multi).Level(level).With().Timestamp().Logger()
|
log.Logger = zerolog.New(multi).Level(level).With().Timestamp().Logger()
|
||||||
|
|
||||||
|
if !utils.SliceContains([]string{"trace", "debug", "info", "warn", "error", "fatal", "panic"}, strings.ToLower(C.LogLevel)) {
|
||||||
|
log.Warn().Msg("Invalid log level: " + C.LogLevel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckGitVersion(version string) (bool, error) {
|
func CheckGitVersion(version string) (bool, error) {
|
||||||
|
|
|
@ -3,17 +3,26 @@ package models
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/mattn/go-sqlite3"
|
"github.com/mattn/go-sqlite3"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/thomiceli/opengist/internal/config"
|
||||||
|
"github.com/thomiceli/opengist/internal/utils"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
|
|
||||||
func Setup(dbpath string) error {
|
func Setup(dbPath string) error {
|
||||||
var err error
|
var err error
|
||||||
|
journalMode := strings.ToUpper(config.C.SqliteJournalMode)
|
||||||
|
|
||||||
if db, err = gorm.Open(sqlite.Open(dbpath+"?_fk=true"), &gorm.Config{
|
if !utils.SliceContains([]string{"DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"}, journalMode) {
|
||||||
|
log.Warn().Msg("Invalid SQLite journal mode: " + journalMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if db, err = gorm.Open(sqlite.Open(dbPath+"?_fk=true&_journal_mode="+journalMode), &gorm.Config{
|
||||||
Logger: logger.Default.LogMode(logger.Silent),
|
Logger: logger.Default.LogMode(logger.Silent),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
10
internal/utils/slice.go
Normal file
10
internal/utils/slice.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
func SliceContains(slice []string, item string) bool {
|
||||||
|
for _, s := range slice {
|
||||||
|
if s == item {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
1
templates/pages/admin_config.html
vendored
1
templates/pages/admin_config.html
vendored
|
@ -17,6 +17,7 @@
|
||||||
<dt>External URL</dt><dd>{{ .c.ExternalUrl }}</dd>
|
<dt>External URL</dt><dd>{{ .c.ExternalUrl }}</dd>
|
||||||
<dt>Opengist home</dt><dd>{{ .c.OpengistHome }}</dd>
|
<dt>Opengist home</dt><dd>{{ .c.OpengistHome }}</dd>
|
||||||
<dt>DB filename</dt><dd>{{ .c.DBFilename }}</dd>
|
<dt>DB filename</dt><dd>{{ .c.DBFilename }}</dd>
|
||||||
|
<dt>SQLite Journal Mode</dt><dd>{{ .c.SqliteJournalMode }}</dd>
|
||||||
<div class="relative col-span-3 mt-4">
|
<div class="relative col-span-3 mt-4">
|
||||||
<div class="absolute inset-0 flex items-center" aria-hidden="true">
|
<div class="absolute inset-0 flex items-center" aria-hidden="true">
|
||||||
<div class="w-full border-t border-gray-300"></div>
|
<div class="w-full border-t border-gray-300"></div>
|
||||||
|
|
Loading…
Reference in a new issue