Skip to content

Commit 57f31ec

Browse files
csoulsLinkinStars
authored andcommitted
fix: expand avatar column length from 1024 to 2048
The avatar column was too short to store long URLs from external OAuth providers. When users log in via connector-google plugin, the Google profile picture URL can exceed 1024 characters, causing a database error: Error 1406 (22001): Data too long for column 'avatar' at row 1 This change expands the avatar column from VARCHAR(1024) to VARCHAR(2048). Note: While URLs can technically exceed 2048 characters per specification, 2048 is the practical limit supported by most browsers and services. URLs longer than 2048 characters are extremely rare in real-world usage.
1 parent c8908b7 commit 57f31ec

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(1024) avatar"`
63+
Avatar string `xorm:"not null default '' VARCHAR(2048) 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
@@ -104,6 +104,7 @@ var migrations = []Migration{
104104
NewMigration("v1.5.1", "add plugin kv storage", addPluginKVStorage, true),
105105
NewMigration("v1.6.0", "move user config to interface", moveUserConfigToInterface, true),
106106
NewMigration("v1.7.0", "add optional tags", addOptionalTags, true),
107+
NewMigration("v1.7.1", "expand avatar column length", expandAvatarColumnLength, false),
107108
}
108109

109110
func GetMigrations() []Migration {

internal/migrations/v29.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+
"xorm.io/xorm"
27+
)
28+
29+
func expandAvatarColumnLength(ctx context.Context, x *xorm.Engine) error {
30+
type User struct {
31+
Avatar string `xorm:"not null default '' VARCHAR(2048) avatar"`
32+
}
33+
if err := x.Context(ctx).Sync(new(User)); err != nil {
34+
return fmt.Errorf("expand avatar column length failed: %w", err)
35+
}
36+
return nil
37+
}

0 commit comments

Comments
 (0)