Skip to content

Commit 95cce88

Browse files
fix: change avatar column type to TEXT to support long URLs
1 parent fca80ab commit 95cce88

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

internal/entity/user_entity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type User struct {
6060
Status int `xorm:"not null default 1 INT(11) status"`
6161
AuthorityGroup int `xorm:"not null default 1 INT(11) authority_group"`
6262
DisplayName string `xorm:"not null default '' VARCHAR(30) display_name"`
63-
Avatar string `xorm:"not null default '' VARCHAR(2048) avatar"`
63+
Avatar string `xorm:"not null default '' TEXT avatar"`
6464
Mobile string `xorm:"not null VARCHAR(20) mobile"`
6565
Bio string `xorm:"not null TEXT bio"`
6666
BioHTML string `xorm:"not null TEXT bio_html"`

internal/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ var migrations = []Migration{
107107
NewMigration("v1.7.2", "expand avatar column length", expandAvatarColumnLength, false),
108108
NewMigration("v1.8.0", "change admin menu", updateAdminMenuSettings, true),
109109
NewMigration("v1.8.1", "ai feat", aiFeat, true),
110+
NewMigration("v1.8.2", "change avatar type to text", updateAvatarType, false),
110111
}
111112

112113
func GetMigrations() []Migration {

internal/migrations/v32.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package migrations
21+
22+
import (
23+
"context"
24+
"fmt"
25+
26+
"github.com/apache/answer/internal/entity"
27+
"xorm.io/xorm"
28+
)
29+
30+
func updateAvatarType(ctx context.Context, x *xorm.Engine) error {
31+
// Sync the User struct to the database.
32+
// Since you changed the struct to use TEXT, this will update the column type.
33+
if err := x.Context(ctx).Sync(new(entity.User)); err != nil {
34+
return fmt.Errorf("sync user table failed: %w", err)
35+
}
36+
return nil
37+
}

0 commit comments

Comments
 (0)