From 69d374435b0aa9e4c6891e0072ba8e6241696a8e Mon Sep 17 00:00:00 2001 From: floss4good Date: Fri, 27 Jun 2025 15:47:58 +0200 Subject: [PATCH] fix: abuse reports string data types (#8267) Follow-up of !6977 I was fooled by the fact that for SQLite the columns corresponding to `string` fields were created as `TEXT`; but this is not the case for PostgreSQL and MariaDB/MySQL. According to XORM default mapping rules[^1] _String is corresponding to varchar(255)_. Therefore `abuse_report`.`remarks` should be of type `VARCHAR(500)` and `abuse_report_shadow_copy`.`raw_value` of type `LONGTEXT`. ### Testing I have dropped the affected columns (or the entire tables) and checked that for PostgreSQL and MariaDB they are created with the correct type and also manually tested the abusive content reporting functionality in order to make sure that no DB error will be returned if for 'Remarks' a text longer than 255 characters is submitted or when a (big) shadow copy is created. [^1]: https://xorm.io/docs/chapter-02/4.columns/ Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8267 Reviewed-by: Gusted Co-authored-by: floss4good Co-committed-by: floss4good --- models/moderation/abuse_report.go | 2 +- models/moderation/shadow_copy.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/moderation/abuse_report.go b/models/moderation/abuse_report.go index dadd61a95e..3a6244ef4c 100644 --- a/models/moderation/abuse_report.go +++ b/models/moderation/abuse_report.go @@ -100,7 +100,7 @@ type AbuseReport struct { // The abuse category selected by the reporter. Category AbuseCategoryType `xorm:"INDEX NOT NULL"` // Remarks provided by the reporter. - Remarks string + Remarks string `xorm:"VARCHAR(500)"` // The ID of the corresponding shadow-copied content when exists; otherwise null. ShadowCopyID sql.NullInt64 `xorm:"DEFAULT NULL"` CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` diff --git a/models/moderation/shadow_copy.go b/models/moderation/shadow_copy.go index cdd8f69c52..d363610a48 100644 --- a/models/moderation/shadow_copy.go +++ b/models/moderation/shadow_copy.go @@ -17,7 +17,7 @@ import ( type AbuseReportShadowCopy struct { ID int64 `xorm:"pk autoincr"` - RawValue string `xorm:"NOT NULL"` + RawValue string `xorm:"LONGTEXT NOT NULL"` // A JSON with relevant fields from user, repository, issue or comment table. CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"` }