Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong table name #30557

Merged
merged 15 commits into from
Apr 23, 2024
7 changes: 6 additions & 1 deletion models/auth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import (
"github.com/stretchr/testify/assert"
)

//////////////////// Application
func TestApplicationTableName(t *testing.T) {
e := unittest.GetXORMEngine()
tableInfo, err := e.TableInfo(new(auth_model.OAuth2Application))
assert.NoError(t, err)
assert.EqualValues(t, "oauth2_application", tableInfo.Name)
}
lunny marked this conversation as resolved.
Show resolved Hide resolved

func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ var migrations = []Migration{
NewMigration("Add missing field of commit status summary table", v1_23.AddCommitStatusSummary2),
// v297 -> v298
NewMigration("Add everyone_access_mode for repo_unit", v1_23.AddRepoUnitEveryoneAccessMode),
// v298 -> v299
NewMigration("Drop wrongly created table o_auth2_application", v1_23.DropWronglyCreatedTable),
}

// GetCurrentDBVersion returns the current db version
Expand Down
3 changes: 2 additions & 1 deletion models/migrations/v1_18/v230.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
// AddConfidentialColumnToOAuth2ApplicationTable: add ConfidentialClient column, setting existing rows to true
func AddConfidentialClientColumnToOAuth2ApplicationTable(x *xorm.Engine) error {
type OAuth2Application struct {
ID int64
ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"`
}

return x.Sync(new(OAuth2Application))
return x.Table("oauth2_application").Sync(new(OAuth2Application))
lunny marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 10 additions & 6 deletions models/migrations/v1_18/v230_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
// premigration
type OAuth2Application struct {
ID int64
}
// premigration
type OAuth2Application struct {
lunny marked this conversation as resolved.
Show resolved Hide resolved
ID int64
}

func (OAuth2Application) TableName() string {
return "oauth2_application"
}

func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
// Prepare and load the testing database
x, deferable := base.PrepareTestEnv(t, 0, new(OAuth2Application))
defer deferable()
Expand All @@ -36,7 +40,7 @@ func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
}

got := []ExpectedOAuth2Application{}
if err := x.Table("o_auth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) {
if err := x.Table("oauth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) {
lunny marked this conversation as resolved.
Show resolved Hide resolved
return
}

Expand Down
10 changes: 10 additions & 0 deletions models/migrations/v1_23/v298.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_23 //nolint

import "xorm.io/xorm"

func DropWronglyCreatedTable(x *xorm.Engine) error {
return x.DropTables("o_auth2_application")
}