feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
@@ -14,6 +14,9 @@ var ErrNavigationBudget = errors.New("navigation snapshot exceeds its bounded bu
|
||||
// A database-backed generation observes other processes and CLI writes too.
|
||||
// It invalidates data caches, never caches a Principal's authorization result.
|
||||
func (s *Store) ensureNavigationSchema() error {
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
return s.ensurePostgreSQLPublication(context.Background())
|
||||
}
|
||||
if _, err := s.DB.Exec(`CREATE TABLE IF NOT EXISTS navigation_generation(id INTEGER PRIMARY KEY CHECK(id=1),version INTEGER NOT NULL); INSERT OR IGNORE INTO navigation_generation VALUES(1,1)`); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -40,7 +43,8 @@ func (s *Store) ensureNavigationSchema() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) NavigationGeneration(ctx context.Context) (int64, error) {
|
||||
func (s *Store) NavigationGeneration(ctx context.Context) (_ int64, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("NavigationGeneration", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
var version int64
|
||||
@@ -48,10 +52,11 @@ func (s *Store) NavigationGeneration(ctx context.Context) (int64, error) {
|
||||
return version, err
|
||||
}
|
||||
|
||||
func (s *Store) NavigationPaths(ctx context.Context, domain string) ([]string, error) {
|
||||
func (s *Store) NavigationPaths(ctx context.Context, domain string) (_ []string, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("NavigationPaths", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT path FROM paths WHERE domain_uuid=? ORDER BY path LIMIT ?`, domain, MaxNavigationEntries+1)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT path FROM paths WHERE domain_uuid=`+s.sqlParam(1)+` ORDER BY path LIMIT `+s.sqlParam(2), domain, MaxNavigationEntries+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -77,13 +82,19 @@ type PublishedNavigationPage struct {
|
||||
Revision Revision
|
||||
}
|
||||
|
||||
func (s *Store) PublicNavigation(ctx context.Context, domain string) ([]PublishedNavigationPage, error) {
|
||||
func (s *Store) PublicNavigation(ctx context.Context, domain string) (_ []PublishedNavigationPage, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("PublicNavigation", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||
defer cancel()
|
||||
// Same live binding/head/epoch checks as AnonymousRevision. No canonical
|
||||
// bodies, historical revisions, unapproved names or private child counts.
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT DISTINCT e.path,r.uuid,r.object_uuid,r.document_hash,COALESCE(NULLIF(r.lang,''),'und'),COALESCE(NULLIF(r.content_type,''),'text/html; charset=utf-8'),COALESCE(r.filename,''),r.created_at_ms `+anonymousRevisionFromSQL+`
|
||||
ORDER BY e.path,r.created_at_ms DESC,r.uuid LIMIT ?`, domain, MaxNavigationEntries+1)
|
||||
tx, err := s.DB.BeginTx(ctx, s.policyReadOptions())
|
||||
if err != nil {
|
||||
return nil, s.sqlError("public navigation", err)
|
||||
}
|
||||
defer tx.Rollback()
|
||||
rows, err := tx.QueryContext(ctx, `SELECT DISTINCT e.path,r.uuid,r.object_uuid,r.document_hash,COALESCE(NULLIF(r.lang,''),'und'),COALESCE(NULLIF(r.content_type,''),'text/html; charset=utf-8'),COALESCE(r.filename,''),r.created_at_ms `+s.anonymousRevisionFromSQL()+`
|
||||
ORDER BY e.path,r.created_at_ms DESC,r.uuid LIMIT `+s.sqlParam(2), domain, MaxNavigationEntries+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -109,7 +120,7 @@ func (s *Store) PublicNavigation(ctx context.Context, domain string) ([]Publishe
|
||||
return nil, err
|
||||
}
|
||||
rows.Close()
|
||||
automatic, err := s.automaticPublicPages(ctx, domain, "")
|
||||
automatic, err := s.automaticPublicPagesTx(ctx, tx, domain, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -132,11 +143,24 @@ func (s *Store) PublicNavigation(ctx context.Context, domain string) ([]Publishe
|
||||
return out, nil
|
||||
}
|
||||
|
||||
const anonymousRevisionFromSQL = `FROM locality_publication_entries e JOIN locality_publication_manifests m ON m.domain_uuid=e.domain_uuid AND m.node_kind=e.node_kind AND m.node_uuid=e.node_uuid
|
||||
func (s *Store) anonymousRevisionFromSQL() string {
|
||||
return `FROM locality_publication_entries e JOIN locality_publication_manifests m ON m.domain_uuid=e.domain_uuid AND m.node_kind=e.node_kind AND m.node_uuid=e.node_uuid
|
||||
JOIN paths p ON p.domain_uuid=e.domain_uuid AND p.path=e.path AND p.object_uuid=e.object_uuid
|
||||
JOIN revisions r ON r.uuid=e.revision_uuid AND r.object_uuid=e.object_uuid AND r.document_hash=e.document_hash AND COALESCE(NULLIF(r.lang,''),'und')=e.lang
|
||||
JOIN domains d ON d.uuid=e.domain_uuid AND d.enabled=1
|
||||
WHERE e.domain_uuid=? AND m.epoch=COALESCE((SELECT version FROM city_governance_epochs WHERE domain_uuid=e.domain_uuid),0)
|
||||
JOIN campuses c ON c.uuid=d.campus_uuid AND c.enabled=1
|
||||
WHERE e.domain_uuid=` + s.sqlParam(1) + ` AND m.epoch=COALESCE((SELECT version FROM city_governance_epochs WHERE domain_uuid=e.domain_uuid),0)
|
||||
AND m.topology_version=COALESCE((SELECT version FROM domain_topology_versions WHERE domain_uuid=e.domain_uuid),1)
|
||||
AND (SELECT value FROM config WHERE domain_uuid=e.domain_uuid AND key='authorization_mode')='enforcing'
|
||||
AND r.uuid=(SELECT head.uuid FROM revisions head WHERE head.object_uuid=r.object_uuid AND COALESCE(NULLIF(head.lang,''),'und')=e.lang ORDER BY head.created_at_ms DESC,head.rowid DESC LIMIT 1)`
|
||||
AND r.uuid=(SELECT head.uuid FROM revisions head WHERE head.object_uuid=r.object_uuid AND COALESCE(NULLIF(head.lang,''),'und')=e.lang ORDER BY ` + s.revisionHeadOrder("head.") + ` LIMIT 1)`
|
||||
}
|
||||
|
||||
// Match each backend's existing canonical head ordering. Legacy SQLite uses
|
||||
// insertion rowid; native PostgreSQL metadata uses UUID as its stable tie-break.
|
||||
func (s *Store) revisionHeadOrder(prefix string) string {
|
||||
tie := "rowid"
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
tie = "uuid"
|
||||
}
|
||||
return prefix + "created_at_ms DESC," + prefix + tie + " DESC"
|
||||
}
|
||||
Reference in new issue
Block a user