Document that the server can use sqlite

This commit is contained in:
David Dworken 2022-11-16 20:54:47 -08:00
parent 4aacd8b5e2
commit fd3d932e9d
No known key found for this signature in database
2 changed files with 6 additions and 9 deletions

View File

@ -106,7 +106,11 @@ Download the latest binary from [Github Releases](https://github.com/ddworken/hi
<summary>Self-Hosting</summary> <summary>Self-Hosting</summary>
By default, hiSHtory relies on a backend for syncing. All data is end-to-end encrypted, so the backend can't view your history. By default, hiSHtory relies on a backend for syncing. All data is end-to-end encrypted, so the backend can't view your history.
But if you'd like to self-host the hishtory backend, you can! The backend is a simple go binary in `backend/server/server.go` that uses postgres to store data. Check out the [`docker-compose.yml`](https://github.com/ddworken/hishtory/blob/master/backend/server/docker-compose.yml) file for an example config to start a hiSHtory server and how to configure it. But if you'd like to self-host the hishtory backend, you can! The backend is a simple go binary in `backend/server/server.go`. It can either use SQLite or Postgres for persistence.
Check out the [`docker-compose.yml`](https://github.com/ddworken/hishtory/blob/master/backend/server/docker-compose.yml) file for an example config to start a hiSHtory server using postgres.
If you want to use a SQLite backend, you can do so by setting the `HISHTORY_SQLITE_DB` environment variable to point to a file. It will then create a SQLite DB at the given location.
</details> </details>
<details> <details>

View File

@ -8,7 +8,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/user"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -371,11 +370,7 @@ func wipeDbHandler(w http.ResponseWriter, r *http.Request) {
} }
func isTestEnvironment() bool { func isTestEnvironment() bool {
u, err := user.Current() return os.Getenv("HISHTORY_TEST") != ""
if err != nil {
panic(err)
}
return os.Getenv("HISHTORY_TEST") != "" || u.Username == "david"
} }
func OpenDB() (*gorm.DB, error) { func OpenDB() (*gorm.DB, error) {
@ -394,7 +389,6 @@ func OpenDB() (*gorm.DB, error) {
} }
var sqliteDb string var sqliteDb string
if os.Getenv("HISHTORY_SQLITE_DB") != "" { if os.Getenv("HISHTORY_SQLITE_DB") != "" {
sqliteDb = os.Getenv("HISHTORY_SQLITE_DB") sqliteDb = os.Getenv("HISHTORY_SQLITE_DB")
} }
@ -411,7 +405,6 @@ func OpenDB() (*gorm.DB, error) {
} }
db, err = gorm.Open(postgres.Open(postgresDb), &gorm.Config{}) db, err = gorm.Open(postgres.Open(postgresDb), &gorm.Config{})
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to connect to the DB: %v", err) return nil, fmt.Errorf("failed to connect to the DB: %v", err)
} }