Refactor architecture into eight components and consolidate reliability work
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s

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.
This commit is contained in:
Anya Tokugawa committed 2026-11-01 15:23:31 +09:00
1 parent 9dd425f765
commit d5d21b7841
302 files changed
+20037 -3492

No files matched your search

+87 -90
View File
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"database/sql"
"encoding/hex"
"fmt"
)
func Migrate(
@@ -96,54 +97,21 @@ func Migrate(
}
}
alterStmts := []string{
`
ALTER TABLE paths
ADD COLUMN created_at INTEGER
`,
`
ALTER TABLE objects
ADD COLUMN created_at INTEGER
`,
`
ALTER TABLE revisions
ADD COLUMN created_at INTEGER
`,
`
ALTER TABLE revisions
ADD COLUMN document_hash TEXT
`,
`
ALTER TABLE revisions
ADD COLUMN lang TEXT NOT NULL DEFAULT 'und'
`,
`
ALTER TABLE revisions
ADD COLUMN created_at_ms INTEGER
`,
`
ALTER TABLE revisions
ADD COLUMN content_type TEXT NOT NULL DEFAULT 'text/html; charset=utf-8'
`,
`
ALTER TABLE revisions
ADD COLUMN filename TEXT NOT NULL DEFAULT ''
`,
`
ALTER TABLE tags
ADD COLUMN created_at INTEGER
`,
columns := []struct{ table, name, declaration string }{
{"paths", "created_at", "INTEGER"},
{"objects", "created_at", "INTEGER"},
{"revisions", "created_at", "INTEGER"},
{"revisions", "document_hash", "TEXT"},
{"revisions", "lang", "TEXT NOT NULL DEFAULT 'und'"},
{"revisions", "created_at_ms", "INTEGER"},
{"revisions", "content_type", "TEXT NOT NULL DEFAULT 'text/html; charset=utf-8'"},
{"revisions", "filename", "TEXT NOT NULL DEFAULT ''"},
{"tags", "created_at", "INTEGER"},
}
for _, stmt := range alterStmts {
_, _ = db.Exec(stmt)
for _, column := range columns {
if err := ensureSQLiteColumn(db, column.table, column.name, column.declaration); err != nil {
return err
}
}
if err := migrateRevisionMetadata(db); err != nil {
@@ -185,54 +153,47 @@ func migrateRevisionMetadata(db *sql.DB) error {
return nil
}
rows, err := db.Query(`
SELECT
uuid,
COALESCE(body, '')
FROM revisions
WHERE document_hash IS NULL
OR document_hash = ''
`)
if err != nil {
return err
}
type legacyRevision struct {
uuid string
body string
}
var revisions []legacyRevision
for rows.Next() {
var revision legacyRevision
if err := rows.Scan(&revision.uuid, &revision.body); err != nil {
// Fetch only identifiers in batches, then hydrate one legacy body at a
// time. The old implementation accumulated all payloads in memory.
lastUUID := ""
for {
rows, err := db.Query(`SELECT uuid FROM revisions WHERE uuid>? AND (document_hash IS NULL OR document_hash='') ORDER BY uuid LIMIT 128`, lastUUID)
if err != nil {
return err
}
var ids []string
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
rows.Close()
return err
}
ids = append(ids, id)
}
if err := rows.Err(); err != nil {
rows.Close()
return err
}
revisions = append(revisions, revision)
}
if err := rows.Close(); err != nil {
return err
}
for _, revision := range revisions {
sum := sha256.Sum256([]byte(revision.body))
documentHash := hex.EncodeToString(sum[:])
if _, err := db.Exec(`
UPDATE revisions
SET document_hash = ?
WHERE uuid = ?
`, documentHash, revision.uuid); err != nil {
if err := rows.Close(); err != nil {
return err
}
for _, id := range ids {
var body string
if err := db.QueryRow(`SELECT COALESCE(body,'') FROM revisions WHERE uuid=?`, id).Scan(&body); err != nil {
return err
}
sum := sha256.Sum256([]byte(body))
if _, err := db.Exec(`UPDATE revisions SET document_hash=? WHERE uuid=? AND (document_hash IS NULL OR document_hash='')`, hex.EncodeToString(sum[:]), id); err != nil {
return err
}
lastUUID = id
}
if len(ids) < 128 {
break
}
}
if _, err = db.Exec(`
if _, err := db.Exec(`
UPDATE revisions
SET
lang = COALESCE(NULLIF(lang, ''), 'und'),
@@ -247,7 +208,7 @@ func migrateRevisionMetadata(db *sql.DB) error {
return err
}
if _, err = db.Exec(`
if _, err := db.Exec(`
CREATE INDEX IF NOT EXISTS idx_revisions_object_created
ON revisions (
object_uuid,
@@ -257,9 +218,45 @@ func migrateRevisionMetadata(db *sql.DB) error {
return err
}
_, err = db.Exec(`
_, err := db.Exec(`
INSERT OR IGNORE INTO schema_migrations (name, applied_at)
VALUES ('revision_metadata_v1', strftime('%s','now'))
`)
return err
}
func sqliteColumnExists(database *sql.DB, table, column string) (bool, error) {
// All identifiers originate in the fixed legacy bootstrap above.
rows, err := database.Query(fmt.Sprintf("PRAGMA table_info(%q)", table))
if err != nil {
return false, err
}
defer rows.Close()
found := false
for rows.Next() {
var cid, notNull, primaryKey int
var name, kind string
var defaultValue any
if err := rows.Scan(&cid, &name, &kind, &notNull, &defaultValue, &primaryKey); err != nil {
return false, err
}
found = found || name == column
}
return found, rows.Err()
}
func ensureSQLiteColumn(database *sql.DB, table, column, declaration string) error {
exists, err := sqliteColumnExists(database, table, column)
if err != nil || exists {
return err
}
_, err = database.Exec(fmt.Sprintf("ALTER TABLE %q ADD COLUMN %q %s", table, column, declaration))
if err != nil {
// Only tolerate another bootstrap adding the exact column concurrently.
if exists, checkErr := sqliteColumnExists(database, table, column); checkErr == nil && exists {
return nil
}
return fmt.Errorf("add column %s.%s: %w", table, column, err)
}
return nil
}