- commit
- 691db43
- parent
- 77c71a2
- author
- Eric Bower
- date
- 2022-08-23 03:23:23 +0000 UTC
refactor(all): making sure every post has shasum
1 files changed,
+53,
-0
+53,
-0
1@@ -0,0 +1,53 @@
2+package main
3+
4+import (
5+ "log"
6+ "os"
7+
8+ "git.sr.ht/~erock/pico/db/postgres"
9+ "git.sr.ht/~erock/pico/shared"
10+ "git.sr.ht/~erock/pico/wish/cms/config"
11+ "go.uber.org/zap"
12+)
13+
14+func createLogger() *zap.SugaredLogger {
15+ logger, err := zap.NewProduction()
16+ if err != nil {
17+ log.Fatal(err)
18+ }
19+
20+ return logger.Sugar()
21+}
22+
23+func main() {
24+ logger := createLogger()
25+ picoCfg := config.NewConfigCms()
26+ picoCfg.Logger = logger
27+ picoCfg.DbURL = os.Getenv("DATABASE_URL")
28+ picoDb := postgres.NewDB(picoCfg)
29+
30+ logger.Info("fetching all posts")
31+ posts, err := picoDb.FindPosts()
32+ if err != nil {
33+ panic(err)
34+ }
35+
36+ empty := 0
37+ diff := 0
38+ for _, post := range posts {
39+ nextShasum := shared.Shasum([]byte(post.Text))
40+ if post.Shasum == "" {
41+ empty += 1
42+ } else if post.Shasum != nextShasum {
43+ diff += 1
44+ }
45+ post.Shasum = nextShasum
46+
47+ _, err := picoDb.UpdatePost(post)
48+ if err != nil {
49+ panic(err)
50+ }
51+ }
52+
53+ logger.Infof("empty (%d), diff (%d)", empty, diff)
54+}