Monorepo for Tangled tangled.org

knotserver: add repo DID migration on startup #1144

open opened by oyster.cafe targeting master from oyster.cafe/tangled-core: master
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:3fwecdnvtcscjnrx2p4n7alz/sh.tangled.repo.pull/3mgprvt2exw22
+22 -30
Interdiff #3 #4
appview/state/router.go

This file has not been changed.

eventconsumer/consumer.go

This file has not been changed.

knotserver/events.go

This file has not been changed.

+19 -30
knotserver/migrate.go
··· 25 25 oldPath string 26 26 } 27 27 28 - func scanLegacyRepos(scanPath string, d *db.DB, logger *slog.Logger) []legacyRepo { 29 - entries, err := os.ReadDir(scanPath) 28 + func scanLegacyRepos(scanPath string, logger *slog.Logger) []legacyRepo { 29 + topEntries, err := os.ReadDir(scanPath) 30 30 if err != nil { 31 31 logger.Error("reading scan path", "error", err) 32 32 return nil 33 33 } 34 34 35 - return collectLegacyEntries(entries, scanPath, d, logger) 36 - } 37 - 38 - func collectLegacyEntries(entries []os.DirEntry, scanPath string, d *db.DB, logger *slog.Logger) []legacyRepo { 39 35 var repos []legacyRepo 40 - for _, entry := range entries { 36 + for _, entry := range topEntries { 41 37 if !entry.IsDir() || !strings.HasPrefix(entry.Name(), "did:") { 42 38 continue 43 39 } ··· 54 50 continue 55 51 } 56 52 57 - repos = append(repos, collectReposInOwnerDir(subEntries, entry.Name(), ownerPath, d, logger)...) 58 - } 59 - return repos 60 - } 61 - 62 - func collectReposInOwnerDir(entries []os.DirEntry, ownerDid, ownerPath string, d *db.DB, logger *slog.Logger) []legacyRepo { 63 - var repos []legacyRepo 64 - for _, sub := range entries { 65 - if !sub.IsDir() { 66 - continue 67 - } 68 - 69 - subPath := filepath.Join(ownerPath, sub.Name()) 70 - if _, err := os.Stat(filepath.Join(subPath, "HEAD")); err != nil { 71 - logger.Warn("skipping non-repo directory", "path", subPath) 72 - continue 53 + ownerDid := entry.Name() 54 + for _, sub := range subEntries { 55 + if !sub.IsDir() { 56 + continue 57 + } 58 + subPath := filepath.Join(ownerPath, sub.Name()) 59 + if _, statErr := os.Stat(filepath.Join(subPath, "HEAD")); statErr != nil { 60 + logger.Warn("skipping non-repo directory", "path", subPath) 61 + continue 62 + } 63 + repos = append(repos, legacyRepo{ 64 + ownerDid: ownerDid, 65 + repoName: sub.Name(), 66 + oldPath: subPath, 67 + }) 73 68 } 74 - 75 - repos = append(repos, legacyRepo{ 76 - ownerDid: ownerDid, 77 - repoName: sub.Name(), 78 - oldPath: subPath, 79 - }) 80 69 } 81 70 return repos 82 71 } 83 72 84 73 func migrateReposOnStartup(ctx context.Context, c *config.Config, d *db.DB, e *rbac.Enforcer, n *notifier.Notifier, logger *slog.Logger) { 85 - repos := scanLegacyRepos(c.Repo.ScanPath, d, logger) 74 + repos := scanLegacyRepos(c.Repo.ScanPath, logger) 86 75 if len(repos) == 0 { 87 76 logger.Info("no legacy repos found, migration complete") 88 77 return
knotserver/server.go

This file has not been changed.

spindle/stream.go

This file has not been changed.

+1
appview/db/db.go
··· 34 34 "_journal_mode=WAL", 35 35 "_synchronous=NORMAL", 36 36 "_auto_vacuum=incremental", 37 + "_busy_timeout=5000", 37 38 } 38 39 39 40 logger := log.FromContext(ctx)
+1
knotserver/db/db.go
··· 25 25 "_journal_mode=WAL", 26 26 "_synchronous=NORMAL", 27 27 "_auto_vacuum=incremental", 28 + "_busy_timeout=5000", 28 29 } 29 30 30 31 logger := log.FromContext(ctx)
+1
spindle/db/db.go
··· 18 18 "_journal_mode=WAL", 19 19 "_synchronous=NORMAL", 20 20 "_auto_vacuum=incremental", 21 + "_busy_timeout=5000", 21 22 } 22 23 23 24 db, err := sql.Open("sqlite3", dbPath+"?"+strings.Join(opts, "&"))

History

12 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
knotserver: add repo DID migration on startup
merge conflicts detected
expand
  • go.mod:34
  • go.sum:339
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 1 comment
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments
1 commit
expand
knotserver: add repo DID migration on startup
expand 0 comments