feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s

This commit is contained in:
Anya Tokugawa committed 2026-11-15 05:47:14 +09:00
1 parent 96065d1e89
commit 0ba1dcfef0
243 files changed
+21441 -3090

No files matched your search

+37 -15
View File
@@ -1,11 +1,14 @@
package store
import (
"context"
"database/sql"
"errors"
"strings"
"time"
"pageswiki/internal/db"
"github.com/google/uuid"
)
@@ -23,13 +26,18 @@ type BrowserNavigationLink struct {
}
func (s *Store) EnsureBrowserNavigationSchema() error {
if s.sqlBackend == storePostgreSQL {
return db.ApplyPostgreSQLMigrations(context.Background(), s.DB, "store-browser-navigation", []db.PostgreSQLMigration{{Version: 1, Name: "browser navigator links", Statements: []string{
`CREATE TABLE browser_navigation_links(uuid TEXT COLLATE "C" PRIMARY KEY,domain_uuid TEXT COLLATE "C" NOT NULL,principal_uuid TEXT COLLATE "C" NOT NULL,label TEXT NOT NULL,path TEXT COLLATE "C" NOT NULL,is_directory INTEGER NOT NULL DEFAULT 0,position BIGINT NOT NULL DEFAULT 0,created_at_ms BIGINT NOT NULL,updated_at_ms BIGINT NOT NULL,UNIQUE(domain_uuid,principal_uuid,path))`,
}, Assertions: []string{`SELECT uuid,domain_uuid,principal_uuid,label,path,is_directory,position,created_at_ms,updated_at_ms FROM browser_navigation_links WHERE 1=0`}}})
}
return s.ensureSchemaComponent("browser-navigation")
}
func (s *Store) ListBrowserNavigationLinks(domainUUID, principalUUID string) ([]BrowserNavigationLink, error) {
rows, err := s.DB.Query(`SELECT uuid,label,path,is_directory,position,updated_at_ms
FROM browser_navigation_links
WHERE domain_uuid=? AND principal_uuid=?
WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+`
ORDER BY position,created_at_ms,uuid`, domainUUID, principalUUID)
if err != nil {
return nil, err
@@ -52,7 +60,8 @@ func (s *Store) AddBrowserNavigationLink(domainUUID, principalUUID, label, path
if domainUUID == "" || principalUUID == "" || label == "" || len(label) > 120 || path == "/" || len(path) > 2048 {
return nil, errors.New("invalid browser navigator link")
}
tx, err := s.DB.Begin()
tx, cancel, err := s.beginPathMutation(domainUUID)
defer cancel()
if err != nil {
return nil, err
}
@@ -60,7 +69,7 @@ func (s *Store) AddBrowserNavigationLink(domainUUID, principalUUID, label, path
var link BrowserNavigationLink
err = tx.QueryRow(`SELECT uuid,label,path,is_directory,position,updated_at_ms
FROM browser_navigation_links
WHERE domain_uuid=? AND principal_uuid=? AND path=?`, domainUUID, principalUUID, path).
WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+` AND path=`+s.sqlParam(3), domainUUID, principalUUID, path).
Scan(&link.UUID, &link.Label, &link.Path, &link.IsDir, &link.Position, &link.UpdatedAt)
if err == nil {
return &link, nil
@@ -70,7 +79,7 @@ func (s *Store) AddBrowserNavigationLink(domainUUID, principalUUID, label, path
}
var count, position int
if err := tx.QueryRow(`SELECT COUNT(*),COALESCE(MAX(position),-1)+1
FROM browser_navigation_links WHERE domain_uuid=? AND principal_uuid=?`, domainUUID, principalUUID).
FROM browser_navigation_links WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2), domainUUID, principalUUID).
Scan(&count, &position); err != nil {
return nil, err
}
@@ -81,7 +90,7 @@ func (s *Store) AddBrowserNavigationLink(domainUUID, principalUUID, label, path
link = BrowserNavigationLink{UUID: uuid.NewString(), Label: label, Path: path, IsDir: isDir, Position: position, UpdatedAt: now}
if _, err := tx.Exec(`INSERT INTO browser_navigation_links
(uuid,domain_uuid,principal_uuid,label,path,is_directory,position,created_at_ms,updated_at_ms)
VALUES(?,?,?,?,?,?,?,?,?)`, link.UUID, domainUUID, principalUUID, link.Label, link.Path, link.IsDir, link.Position, now, now); err != nil {
VALUES(`+s.sqlValues(9)+`)`, link.UUID, domainUUID, principalUUID, link.Label, link.Path, boolToInt(link.IsDir), link.Position, now, now); err != nil {
return nil, err
}
if err := tx.Commit(); err != nil {
@@ -95,8 +104,11 @@ func (s *Store) RenameBrowserNavigationLink(domainUUID, principalUUID, id, label
if label == "" || len(label) > 120 {
return errors.New("invalid browser navigator label")
}
result, err := s.DB.Exec(`UPDATE browser_navigation_links SET label=?,updated_at_ms=?
WHERE uuid=? AND domain_uuid=? AND principal_uuid=?`, label, time.Now().UnixMilli(), id, domainUUID, principalUUID)
if s.ReadOnly {
return ErrReadOnly
}
result, err := s.DB.Exec(`UPDATE browser_navigation_links SET label=`+s.sqlParam(1)+`,updated_at_ms=`+s.sqlParam(2)+`
WHERE uuid=`+s.sqlParam(3)+` AND domain_uuid=`+s.sqlParam(4)+` AND principal_uuid=`+s.sqlParam(5), label, time.Now().UnixMilli(), id, domainUUID, principalUUID)
if err != nil {
return err
}
@@ -108,8 +120,11 @@ func (s *Store) RenameBrowserNavigationLink(domainUUID, principalUUID, id, label
}
func (s *Store) DeleteBrowserNavigationLink(domainUUID, principalUUID, id string) error {
if s.ReadOnly {
return ErrReadOnly
}
result, err := s.DB.Exec(`DELETE FROM browser_navigation_links
WHERE uuid=? AND domain_uuid=? AND principal_uuid=?`, id, domainUUID, principalUUID)
WHERE uuid=`+s.sqlParam(1)+` AND domain_uuid=`+s.sqlParam(2)+` AND principal_uuid=`+s.sqlParam(3), id, domainUUID, principalUUID)
if err != nil {
return err
}
@@ -123,19 +138,26 @@ func (s *Store) DeleteBrowserNavigationLink(domainUUID, principalUUID, id string
// renameBrowserNavigationPathsTx keeps a user's saved navigator targets aligned
// with semantic Path mutations. If the destination was already saved, the
// existing destination link wins and the now-duplicate source link is removed.
func renameBrowserNavigationPathsTx(tx *sql.Tx, domainUUID, oldPath, newPath string, recursive bool) error {
func (s *Store) renameBrowserNavigationPathsTx(tx *sql.Tx, domainUUID, oldPath, newPath string, recursive bool) error {
var tableExists bool
if err := tx.QueryRow(`SELECT EXISTS(
existsSQL := `SELECT EXISTS(
SELECT 1 FROM sqlite_master WHERE type='table' AND name='browser_navigation_links'
)`).Scan(&tableExists); err != nil {
)`
if s.sqlBackend == storePostgreSQL {
existsSQL = `SELECT to_regclass('browser_navigation_links') IS NOT NULL`
}
if err := tx.QueryRow(existsSQL).Scan(&tableExists); err != nil {
return err
}
if !tableExists {
if s.sqlBackend == storePostgreSQL {
return ErrPostgreSQLComponentNotReady
}
return nil
}
rows, err := tx.Query(`SELECT uuid,principal_uuid,path
FROM browser_navigation_links
WHERE domain_uuid=? AND (path=? OR (? AND path>=? AND path<?))
WHERE domain_uuid=`+s.sqlParam(1)+` AND (path=`+s.sqlParam(2)+` OR (`+s.sqlParam(3)+` AND path>=`+s.sqlParam(4)+` AND path<`+s.sqlParam(5)+`))
ORDER BY length(path),path`, domainUUID, oldPath, recursive, oldPath+"/", oldPath+"0")
if err != nil {
return err
@@ -162,9 +184,9 @@ func renameBrowserNavigationPathsTx(tx *sql.Tx, domainUUID, oldPath, newPath str
for _, item := range targets {
var existing string
err := tx.QueryRow(`SELECT uuid FROM browser_navigation_links
WHERE domain_uuid=? AND principal_uuid=? AND path=?`, domainUUID, item.principal, item.next).Scan(&existing)
WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+` AND path=`+s.sqlParam(3), domainUUID, item.principal, item.next).Scan(&existing)
if err == nil && existing != item.id {
if _, err := tx.Exec(`DELETE FROM browser_navigation_links WHERE uuid=?`, item.id); err != nil {
if _, err := tx.Exec(`DELETE FROM browser_navigation_links WHERE uuid=`+s.sqlParam(1), item.id); err != nil {
return err
}
continue
@@ -172,7 +194,7 @@ func renameBrowserNavigationPathsTx(tx *sql.Tx, domainUUID, oldPath, newPath str
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}
if _, err := tx.Exec(`UPDATE browser_navigation_links SET path=?,updated_at_ms=? WHERE uuid=?`, item.next, now, item.id); err != nil {
if _, err := tx.Exec(`UPDATE browser_navigation_links SET path=`+s.sqlParam(1)+`,updated_at_ms=`+s.sqlParam(2)+` WHERE uuid=`+s.sqlParam(3), item.next, now, item.id); err != nil {
return err
}
}