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 }