diff --git a/controller/token_test.go b/controller/token_test.go index 3eea6730..65fd7d95 100644 --- a/controller/token_test.go +++ b/controller/token_test.go @@ -38,6 +38,11 @@ type tokenKeyResponse struct { Key string `json:"key"` } +type sqliteColumnInfo struct { + Name string `gorm:"column:name"` + Type string `gorm:"column:type"` +} + func setupTokenControllerTestDB(t *testing.T) *gorm.DB { t.Helper() @@ -124,6 +129,26 @@ func decodeAPIResponse(t *testing.T, recorder *httptest.ResponseRecorder) tokenA return response } +func TestTokenAutoMigrateUsesVarchar128KeyColumn(t *testing.T) { + db := setupTokenControllerTestDB(t) + + var columns []sqliteColumnInfo + if err := db.Raw("PRAGMA table_info(tokens)").Scan(&columns).Error; err != nil { + t.Fatalf("failed to inspect token table schema: %v", err) + } + + for _, column := range columns { + if column.Name == "key" { + if strings.ToLower(column.Type) != "varchar(128)" { + t.Fatalf("expected key column type varchar(128), got %q", column.Type) + } + return + } + } + + t.Fatal("key column not found in token table schema") +} + func TestGetAllTokensMasksKeyInResponse(t *testing.T) { db := setupTokenControllerTestDB(t) token := seedToken(t, db, 1, "list-token", "abcd1234efgh5678") diff --git a/model/token.go b/model/token.go index 0529e2c7..ab841f60 100644 --- a/model/token.go +++ b/model/token.go @@ -14,7 +14,7 @@ import ( type Token struct { Id int `json:"id"` UserId int `json:"user_id" gorm:"index"` - Key string `json:"key" gorm:"type:char(48);uniqueIndex"` + Key string `json:"key" gorm:"type:varchar(128);uniqueIndex"` Status int `json:"status" gorm:"default:1"` Name string `json:"name" gorm:"index" ` CreatedTime int64 `json:"created_time" gorm:"bigint"`