migrate DB WAL file as well as DB file. make dev leftnav color more subtle

This commit is contained in:
sawka 2023-11-02 14:05:43 -07:00
parent 5708b3f19f
commit 38a1f95115
3 changed files with 26 additions and 3 deletions

View File

@ -1,7 +1,7 @@
@base-color: #eceeec; @base-color: #eceeec;
@base-background: rgba(21, 23, 21, 1); @base-background: rgba(21, 23, 21, 1);
@base-background-transparent: rgba(21, 23, 21, 0.7); @base-background-transparent: rgba(21, 23, 21, 0.7);
@base-background-dev: rgba(57, 0, 78, 0.7); @base-background-dev: rgba(21, 23, 48, 0.7);
@base-border: rgba(241, 246, 243, 0.08); @base-border: rgba(241, 246, 243, 0.08);
@background-session: rgba(13, 13, 13, 0.85); @background-session: rgba(13, 13, 13, 0.85);
@background-session-components: rgba(48, 49, 48, 0.6); @background-session-components: rgba(48, 49, 48, 0.6);

View File

@ -4,8 +4,10 @@
package sstore package sstore
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"io/fs"
"log" "log"
"os" "os"
"strconv" "strconv"
@ -40,11 +42,14 @@ func MakeMigrate() (*migrate.Migrate, error) {
return m, nil return m, nil
} }
func copyFile(srcFile string, dstFile string) error { func copyFile(srcFile string, dstFile string, notFoundOk bool) error {
if srcFile == dstFile { if srcFile == dstFile {
return fmt.Errorf("cannot copy %s to itself", srcFile) return fmt.Errorf("cannot copy %s to itself", srcFile)
} }
srcFd, err := os.Open(srcFile) srcFd, err := os.Open(srcFile)
if notFoundOk && err != nil && errors.Is(err, fs.ErrNotExist) {
return nil
}
if err != nil { if err != nil {
return fmt.Errorf("cannot open %s: %v", err) return fmt.Errorf("cannot open %s: %v", err)
} }
@ -100,10 +105,16 @@ func MigrateUp(targetVersion uint) error {
} }
log.Printf("[db] migrating from %d to %d\n", curVersion, targetVersion) log.Printf("[db] migrating from %d to %d\n", curVersion, targetVersion)
log.Printf("[db] backing up database %s to %s\n", DBFileName, DBFileNameBackup) log.Printf("[db] backing up database %s to %s\n", DBFileName, DBFileNameBackup)
err = copyFile(GetDBName(), GetDBBackupName()) os.Remove(GetDBBackupName()) // don't report error
os.Remove(GetDBWALBackupName()) // don't report error
err = copyFile(GetDBName(), GetDBBackupName(), false)
if err != nil { if err != nil {
return fmt.Errorf("error creating database backup: %v", err) return fmt.Errorf("error creating database backup: %v", err)
} }
err = copyFile(GetDBWALName(), GetDBWALBackupName(), true)
if err != nil {
return fmt.Errorf("error creating database(wal) backup: %v", err)
}
for newVersion := curVersion + 1; newVersion <= targetVersion; newVersion++ { for newVersion := curVersion + 1; newVersion <= targetVersion; newVersion++ {
err = MigrateUpStep(m, newVersion) err = MigrateUpStep(m, newVersion)
if err != nil { if err != nil {

View File

@ -34,7 +34,9 @@ import (
const LineNoHeight = -1 const LineNoHeight = -1
const DBFileName = "waveterm.db" const DBFileName = "waveterm.db"
const DBWALFileName = "waveterm.db-wal"
const DBFileNameBackup = "backup.waveterm.db" const DBFileNameBackup = "backup.waveterm.db"
const DBWALFileNameBackup = "backup.waveterm.db-wal"
const MaxWebShareLineCount = 50 const MaxWebShareLineCount = 50
const MaxWebShareScreenCount = 3 const MaxWebShareScreenCount = 3
const MaxLineStateSize = 4 * 1024 // 4k for now, can raise if needed const MaxLineStateSize = 4 * 1024 // 4k for now, can raise if needed
@ -149,11 +151,21 @@ func GetDBName() string {
return path.Join(scHome, DBFileName) return path.Join(scHome, DBFileName)
} }
func GetDBWALName() string {
scHome := scbase.GetWaveHomeDir()
return path.Join(scHome, DBWALFileName)
}
func GetDBBackupName() string { func GetDBBackupName() string {
scHome := scbase.GetWaveHomeDir() scHome := scbase.GetWaveHomeDir()
return path.Join(scHome, DBFileNameBackup) return path.Join(scHome, DBFileNameBackup)
} }
func GetDBWALBackupName() string {
scHome := scbase.GetWaveHomeDir()
return path.Join(scHome, DBWALFileNameBackup)
}
func IsValidConnectMode(mode string) bool { func IsValidConnectMode(mode string) bool {
return mode == ConnectModeStartup || mode == ConnectModeAuto || mode == ConnectModeManual return mode == ConnectModeStartup || mode == ConnectModeAuto || mode == ConnectModeManual
} }