Files
pages/internal/store/readonly.go
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

39 lines
1.0 KiB
Go

package store
import (
"crypto/sha256"
"database/sql"
"errors"
"os"
"path/filepath"
"strings"
)
var ErrReadOnly = errors.New("DR standby is read-only")
// No migrations, schema repair, key generation or file creation on standby.
func NewReadOnlyWithDocumentRoot(database *sql.DB, root string) (*Store, error) {
var readOnly int
if err := database.QueryRow("PRAGMA query_only").Scan(&readOnly); err != nil {
return nil, err
}
if readOnly != 1 {
return nil, errors.New("standby requires a read-only database connection")
}
st := &Store{DB: database, DocumentRoot: root, childCache: map[string][]string{}, ReadOnly: true}
if encoded := strings.TrimSpace(os.Getenv("PAGESWIKI_AUTH_KEY")); encoded != "" {
sum := sha256.Sum256([]byte(encoded))
st.authKey = sum[:]
} else {
key, err := os.ReadFile(filepath.Join(filepath.Dir(root), "auth.key"))
if err != nil {
return nil, err
}
if len(key) != 32 {
return nil, errors.New("standby requires the original 32-byte auth.key")
}
st.authKey = key
}
return st, nil
}