diff --git a/src/migration/migrations/2021-07-04T204642Z_ReworkPostFields.go b/src/migration/migrations/2021-07-04T204642Z_ReworkPostFields.go
new file mode 100644
index 0000000..603a7f1
--- /dev/null
+++ b/src/migration/migrations/2021-07-04T204642Z_ReworkPostFields.go
@@ -0,0 +1,68 @@
+package migrations
+
+import (
+ "context"
+ "time"
+
+ "git.handmade.network/hmn/hmn/src/migration/types"
+ "git.handmade.network/hmn/hmn/src/oops"
+ "github.com/jackc/pgx/v4"
+)
+
+func init() {
+ registerMigration(ReworkPostFields{})
+}
+
+type ReworkPostFields struct{}
+
+func (m ReworkPostFields) Version() types.MigrationVersion {
+ return types.MigrationVersion(time.Date(2021, 7, 4, 20, 46, 42, 0, time.UTC))
+}
+
+func (m ReworkPostFields) Name() string {
+ return "ReworkPostFields"
+}
+
+func (m ReworkPostFields) Description() string {
+ return "Clean up post and postversion fields"
+}
+
+func (m ReworkPostFields) Up(ctx context.Context, tx pgx.Tx) error {
+ _, err := tx.Exec(ctx, `
+ ALTER TABLE handmade_post
+ DROP depth,
+ DROP slug,
+ DROP author_name,
+ DROP ip,
+ DROP sticky,
+ DROP hits,
+ DROP featured,
+ DROP featurevotes;
+ `)
+ if err != nil {
+ return oops.New(err, "failed to drop unnecessary post fields")
+ }
+
+ _, err = tx.Exec(ctx, `
+ ALTER TABLE handmade_postversion
+ RENAME edit_ip TO ip;
+ ALTER TABLE handmade_postversion
+ RENAME edit_date TO date;
+ `)
+ if err != nil {
+ return oops.New(err, "failed to rename postversion fields")
+ }
+
+ _, err = tx.Exec(ctx, `
+ DROP TABLE handmade_kunenapost;
+ `)
+ if err != nil {
+ return oops.New(err, "failed to drop ancient weirdo table")
+ }
+
+ return nil
+}
+
+func (m ReworkPostFields) Down(ctx context.Context, tx pgx.Tx) error {
+ panic("Implement me")
+}
diff --git a/src/models/post.go b/src/models/post.go
index e0dbcbe..4c476e2 100644
--- a/src/models/post.go
+++ b/src/models/post.go
@@ -18,16 +18,8 @@ type Post struct {
CategoryKind CategoryKind `db:"category_kind"`
- Depth int `db:"depth"` // TODO: Drop this.
- Slug string `db:"slug"` // TODO: Drop this.
- AuthorName string `db:"author_name"` // TODO: Drop this.
- PostDate time.Time `db:"postdate"` // TODO: Drop this.
- IP net.IPNet `db:"ip"` // TODO: Drop this.
- Sticky bool `db:"sticky"` // TODO: Drop this.
- Deleted bool `db:"deleted"`
- Hits int `db:"hits"` // TODO: Drop this.
- Featured bool `db:"featured"` // TODO: Drop this.
- FeatureVotes int `db:"featurevotes"` // TODO: Drop this.
+ PostDate time.Time `db:"postdate"`
+ Deleted bool `db:"deleted"`
Preview string `db:"preview"`
ReadOnly bool `db:"readonly"`
@@ -40,8 +32,8 @@ type PostVersion struct {
TextRaw string `db:"text_raw"`
TextParsed string `db:"text_parsed"`
- EditIP *net.IPNet `db:"edit_ip"`
- EditDate time.Time `db:"edit_date"`
+ IP *net.IPNet `db:"ip"`
+ Date time.Time `db:"date"`
EditReason string `db:"edit_reason"`
EditorID *int `db:"editor_id"`
}
diff --git a/src/templates/mapping.go b/src/templates/mapping.go
index 1f35949..a9fa260 100644
--- a/src/templates/mapping.go
+++ b/src/templates/mapping.go
@@ -29,19 +29,17 @@ func PostToTemplate(p *models.Post, author *models.User, currentTheme string) Po
Author: authorUser,
// No content. A lot of the time we don't have this handy and don't need it. See AddContentVersion.
PostDate: p.PostDate,
-
- IP: p.IP.String(),
}
}
-func (p *Post) AddContentVersion(ver models.PostVersion, editor *models.User, currentTheme string) {
+func (p *Post) AddContentVersion(ver models.PostVersion, editor *models.User) {
p.Content = template.HTML(ver.TextParsed)
+ p.IP = maybeIp(ver.IP)
if editor != nil {
- editorTmpl := UserToTemplate(editor, currentTheme)
+ editorTmpl := UserToTemplate(editor, "theme not required here")
p.Editor = &editorTmpl
- p.EditDate = ver.EditDate
- p.EditIP = maybeIp(ver.EditIP)
+ p.EditDate = ver.Date
p.EditReason = ver.EditReason
}
}
diff --git a/src/templates/src/forum_thread.html b/src/templates/src/forum_thread.html
index 3355b80..c2857be 100644
--- a/src/templates/src/forum_thread.html
+++ b/src/templates/src/forum_thread.html
@@ -87,16 +87,15 @@
Edited by
{{ coalesce .Editor.Name .Editor.Username }}
{{ if $.User }}
- {{ if and $.User.IsStaff .EditIP }}[{{ .EditIP }}]{{ end }}
+ {{ if and $.User.IsStaff .IP }}[{{ .IP }}]{{ end }}
{{ end }}
on {{ timehtml (absolutedate .EditDate) .EditDate }}
{{ with .EditReason }}
Reason: {{ . }}
{{ end }}
- {{ end }}
- {{ if $.User }}
- {{ if $.User.IsStaff }}
+ {{ else if $.User }}
+ {{ if and $.User.IsStaff .IP }}
[{{ .IP }}]
{{ end }}
{{ end }}
diff --git a/src/templates/types.go b/src/templates/types.go
index 53e7368..24d62d5 100644
--- a/src/templates/types.go
+++ b/src/templates/types.go
@@ -84,7 +84,6 @@ type Post struct {
Editor *User
EditDate time.Time
- EditIP string
EditReason string
IP string
diff --git a/src/website/feed.go b/src/website/feed.go
index 0b36cff..0d56bc1 100644
--- a/src/website/feed.go
+++ b/src/website/feed.go
@@ -385,7 +385,7 @@ func fetchAllPosts(c *RequestContext, lineageBuilder *models.CategoryLineageBuil
)
postItem.UUID = uuid.NewSHA1(uuid.NameSpaceURL, []byte(postItem.Url)).URN()
- postItem.LastEditDate = postResult.PostVersion.EditDate
+ postItem.LastEditDate = postResult.PostVersion.Date
postItems = append(postItems, postItem)
}
diff --git a/src/website/forums.go b/src/website/forums.go
index 6da652a..496a35a 100644
--- a/src/website/forums.go
+++ b/src/website/forums.go
@@ -405,7 +405,7 @@ func ForumThread(c *RequestContext) ResponseData {
row := irow.(*postsQueryResult)
post := templates.PostToTemplate(&row.Post, row.Author, c.Theme)
- post.AddContentVersion(row.Ver, row.Editor, c.Theme)
+ post.AddContentVersion(row.Ver, row.Editor)
post.AddUrls(c.CurrentProject.Slug, currentSubforumSlugs, thread.ID, post.ID)
posts = append(posts, post)
diff --git a/src/website/timeline_helper.go b/src/website/timeline_helper.go
index c85bc92..0cf54f4 100644
--- a/src/website/timeline_helper.go
+++ b/src/website/timeline_helper.go
@@ -98,7 +98,7 @@ func PostVersionToWikiTimelineItem(lineageBuilder *models.CategoryLineageBuilder
Type: templates.TimelineTypeWikiEdit,
TypeTitle: TimelineTypeTitleMap[templates.TimelineTypeWikiEdit],
Class: TimelineItemClassMap[templates.TimelineTypeWikiEdit],
- Date: version.EditDate,
+ Date: version.Date,
Url: hmnurl.BuildWikiArticle(project.Slug, thread.ID, thread.Title),
OwnerAvatarUrl: templates.UserAvatarUrl(owner, currentTheme),