Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: change avatar column type to TEXT to support long URLs

maishivamhoo123844c73cd7fbb
diff --git a/internal/entity/user_entity.go b/internal/entity/user_entity.go
index 8e63fc95..5e9eed18 100644
--- a/internal/entity/user_entity.go
+++ b/internal/entity/user_entity.go
@@ -60,7 +60,7 @@ type User struct {
Status int `xorm:"not null default 1 INT(11) status"`
AuthorityGroup int `xorm:"not null default 1 INT(11) authority_group"`
DisplayName string `xorm:"not null default '' VARCHAR(30) display_name"`
- Avatar string `xorm:"not null default '' VARCHAR(2048) avatar"`
+ Avatar string `xorm:"not null default '' TEXT avatar"`
Mobile string `xorm:"not null VARCHAR(20) mobile"`
Bio string `xorm:"not null TEXT bio"`
BioHTML string `xorm:"not null TEXT bio_html"`
diff --git a/internal/migrations/migrations.go b/internal/migrations/migrations.go
index 33453ef1..a1393955 100644
--- a/internal/migrations/migrations.go
+++ b/internal/migrations/migrations.go
@@ -107,6 +107,7 @@ var migrations = []Migration{
NewMigration("v1.7.2", "expand avatar column length", expandAvatarColumnLength, false),
NewMigration("v1.8.0", "change admin menu", updateAdminMenuSettings, true),
NewMigration("v1.8.1", "ai feat", aiFeat, true),
+ NewMigration("v1.8.2", "change avatar type to text", updateAvatarType, false),
}
func GetMigrations() []Migration {
diff --git a/internal/migrations/v32.go b/internal/migrations/v32.go
new file mode 100644
index 00000000..5ef0f0a0
--- /dev/null
+++ b/internal/migrations/v32.go
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package migrations
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/apache/answer/internal/entity"
+ "xorm.io/xorm"
+)
+
+func updateAvatarType(ctx context.Context, x *xorm.Engine) error {
+ // Sync the User struct to the database.
+ // Since you changed the struct to use TEXT, this will update the column type.
+ if err := x.Context(ctx).Sync(new(entity.User)); err != nil {
+ return fmt.Errorf("sync user table failed: %w", err)
+ }
+ return nil
+}