Upgrade xorm to v1.0.0 (#10646)
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
This commit is contained in:
parent
dcaa5643d7
commit
c61b902538
154 changed files with 7195 additions and 5962 deletions
|
@ -207,7 +207,12 @@ func (repo *Repository) refreshAccesses(e Engine, accessMap map[int64]*userAcces
|
|||
// Delete old accesses and insert new ones for repository.
|
||||
if _, err = e.Delete(&Access{RepoID: repo.ID}); err != nil {
|
||||
return fmt.Errorf("delete old accesses: %v", err)
|
||||
} else if _, err = e.Insert(newAccesses); err != nil {
|
||||
}
|
||||
if len(newAccesses) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err = e.Insert(newAccesses); err != nil {
|
||||
return fmt.Errorf("insert new accesses: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -25,6 +25,9 @@ func (opts ListOptions) getPaginatedSession() *xorm.Session {
|
|||
func (opts ListOptions) setSessionPagination(sess *xorm.Session) *xorm.Session {
|
||||
opts.setDefaultValues()
|
||||
|
||||
if opts.PageSize <= 0 {
|
||||
return sess
|
||||
}
|
||||
return sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"xorm.io/core"
|
||||
xormlog "xorm.io/xorm/log"
|
||||
)
|
||||
|
||||
// XORMLogBridge a logger bridge from Logger to xorm
|
||||
|
@ -19,7 +19,7 @@ type XORMLogBridge struct {
|
|||
}
|
||||
|
||||
// NewXORMLogger inits a log bridge for xorm
|
||||
func NewXORMLogger(showSQL bool) core.ILogger {
|
||||
func NewXORMLogger(showSQL bool) xormlog.Logger {
|
||||
return &XORMLogBridge{
|
||||
showSQL: showSQL,
|
||||
logger: log.GetLogger("xorm"),
|
||||
|
@ -72,22 +72,22 @@ func (l *XORMLogBridge) Warnf(format string, v ...interface{}) {
|
|||
}
|
||||
|
||||
// Level get logger level
|
||||
func (l *XORMLogBridge) Level() core.LogLevel {
|
||||
func (l *XORMLogBridge) Level() xormlog.LogLevel {
|
||||
switch l.logger.GetLevel() {
|
||||
case log.TRACE, log.DEBUG:
|
||||
return core.LOG_DEBUG
|
||||
return xormlog.LOG_DEBUG
|
||||
case log.INFO:
|
||||
return core.LOG_INFO
|
||||
return xormlog.LOG_INFO
|
||||
case log.WARN:
|
||||
return core.LOG_WARNING
|
||||
return xormlog.LOG_WARNING
|
||||
case log.ERROR, log.CRITICAL:
|
||||
return core.LOG_ERR
|
||||
return xormlog.LOG_ERR
|
||||
}
|
||||
return core.LOG_OFF
|
||||
return xormlog.LOG_OFF
|
||||
}
|
||||
|
||||
// SetLevel set the logger level
|
||||
func (l *XORMLogBridge) SetLevel(lvl core.LogLevel) {
|
||||
func (l *XORMLogBridge) SetLevel(lvl xormlog.LogLevel) {
|
||||
}
|
||||
|
||||
// ShowSQL set if record SQL
|
||||
|
|
|
@ -22,8 +22,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
)
|
||||
|
||||
// LoginType represents an login type.
|
||||
|
@ -60,11 +60,11 @@ var SecurityProtocolNames = map[ldap.SecurityProtocol]string{
|
|||
|
||||
// Ensure structs implemented interface.
|
||||
var (
|
||||
_ core.Conversion = &LDAPConfig{}
|
||||
_ core.Conversion = &SMTPConfig{}
|
||||
_ core.Conversion = &PAMConfig{}
|
||||
_ core.Conversion = &OAuth2Config{}
|
||||
_ core.Conversion = &SSPIConfig{}
|
||||
_ convert.Conversion = &LDAPConfig{}
|
||||
_ convert.Conversion = &SMTPConfig{}
|
||||
_ convert.Conversion = &PAMConfig{}
|
||||
_ convert.Conversion = &OAuth2Config{}
|
||||
_ convert.Conversion = &SSPIConfig{}
|
||||
)
|
||||
|
||||
// LDAPConfig holds configuration for LDAP login source.
|
||||
|
@ -165,10 +165,10 @@ func (cfg *SSPIConfig) ToDB() ([]byte, error) {
|
|||
type LoginSource struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type LoginType
|
||||
Name string `xorm:"UNIQUE"`
|
||||
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
Cfg core.Conversion `xorm:"TEXT"`
|
||||
Name string `xorm:"UNIQUE"`
|
||||
IsActived bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
IsSyncEnabled bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
Cfg convert.Conversion `xorm:"TEXT"`
|
||||
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
|
|
|
@ -5,32 +5,26 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func changeReviewContentToText(x *xorm.Engine) error {
|
||||
|
||||
if x.Dialect().DBType() == core.MYSQL {
|
||||
switch x.Dialect().URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
|
||||
return err
|
||||
}
|
||||
|
||||
if x.Dialect().DBType() == core.ORACLE {
|
||||
case schemas.ORACLE:
|
||||
_, err := x.Exec("ALTER TABLE review MODIFY content TEXT")
|
||||
return err
|
||||
}
|
||||
|
||||
if x.Dialect().DBType() == core.MSSQL {
|
||||
case schemas.MSSQL:
|
||||
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TEXT")
|
||||
return err
|
||||
}
|
||||
|
||||
if x.Dialect().DBType() == core.POSTGRES {
|
||||
case schemas.POSTGRES:
|
||||
_, err := x.Exec("ALTER TABLE review ALTER COLUMN content TYPE TEXT")
|
||||
return err
|
||||
default:
|
||||
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
|
||||
return nil
|
||||
}
|
||||
|
||||
// SQLite doesn't support ALTER COLUMN, and it seem to already make String to _TEXT_ default so no migration needed
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,17 +8,18 @@ import (
|
|||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func changeU2FCounterType(x *xorm.Engine) error {
|
||||
var err error
|
||||
|
||||
switch x.Dialect().DriverName() {
|
||||
case "mysql":
|
||||
switch x.Dialect().URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
_, err = x.Exec("ALTER TABLE `u2f_registration` MODIFY `counter` BIGINT")
|
||||
case "postgres":
|
||||
case schemas.POSTGRES:
|
||||
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` SET DATA TYPE bigint")
|
||||
case "mssql":
|
||||
case schemas.MSSQL:
|
||||
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` BIGINT")
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@ import (
|
|||
|
||||
// Needed for the MySQL driver
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
"xorm.io/xorm/schemas"
|
||||
|
||||
// Needed for the Postgresql driver
|
||||
_ "github.com/lib/pq"
|
||||
|
@ -127,7 +128,7 @@ func init() {
|
|||
|
||||
gonicNames := []string{"SSL", "UID"}
|
||||
for _, name := range gonicNames {
|
||||
core.LintGonicMapper[name] = true
|
||||
names.LintGonicMapper[name] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +153,7 @@ func NewTestEngine(x *xorm.Engine) (err error) {
|
|||
return fmt.Errorf("Connect to database: %v", err)
|
||||
}
|
||||
|
||||
x.ShowExecTime(true)
|
||||
x.SetMapper(core.GonicMapper{})
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
x.SetLogger(NewXORMLogger(!setting.ProdMode))
|
||||
x.ShowSQL(!setting.ProdMode)
|
||||
return x.StoreEngine("InnoDB").Sync2(tables...)
|
||||
|
@ -166,8 +166,7 @@ func SetEngine() (err error) {
|
|||
return fmt.Errorf("Failed to connect to database: %v", err)
|
||||
}
|
||||
|
||||
x.ShowExecTime(true)
|
||||
x.SetMapper(core.GonicMapper{})
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
// WARNING: for serv command, MUST remove the output to os.stdout,
|
||||
// so use log file to instead print to stdout.
|
||||
x.SetLogger(NewXORMLogger(setting.Database.LogSQL))
|
||||
|
@ -249,21 +248,26 @@ func Ping() error {
|
|||
|
||||
// DumpDatabase dumps all data from database according the special database SQL syntax to file system.
|
||||
func DumpDatabase(filePath string, dbType string) error {
|
||||
var tbs []*core.Table
|
||||
var tbs []*schemas.Table
|
||||
for _, t := range tables {
|
||||
t := x.TableInfo(t)
|
||||
t.Table.Name = t.Name
|
||||
tbs = append(tbs, t.Table)
|
||||
t, err := x.TableInfo(t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tbs = append(tbs, t)
|
||||
}
|
||||
if len(dbType) > 0 {
|
||||
return x.DumpTablesToFile(tbs, filePath, core.DbType(dbType))
|
||||
return x.DumpTablesToFile(tbs, filePath, schemas.DBType(dbType))
|
||||
}
|
||||
return x.DumpTablesToFile(tbs, filePath)
|
||||
}
|
||||
|
||||
// MaxBatchInsertSize returns the table's max batch insert size
|
||||
func MaxBatchInsertSize(bean interface{}) int {
|
||||
t := x.TableInfo(bean)
|
||||
t, err := x.TableInfo(bean)
|
||||
if err != nil {
|
||||
return 50
|
||||
}
|
||||
return 999 / len(t.ColumnsSeq())
|
||||
}
|
||||
|
||||
|
|
|
@ -1072,12 +1072,14 @@ func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Insert(units); err != nil {
|
||||
errRollback := sess.Rollback()
|
||||
if errRollback != nil {
|
||||
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
|
||||
if len(units) > 0 {
|
||||
if _, err = sess.Insert(units); err != nil {
|
||||
errRollback := sess.Rollback()
|
||||
if errRollback != nil {
|
||||
log.Error("UpdateTeamUnits sess.Rollback: %v", errRollback)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
|
|
|
@ -1417,8 +1417,10 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
|
|||
return err
|
||||
}
|
||||
|
||||
if _, err = sess.Insert(units); err != nil {
|
||||
return err
|
||||
if len(units) > 0 {
|
||||
if _, err = sess.Insert(units); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/unknwon/com"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/convert"
|
||||
)
|
||||
|
||||
// RepoUnit describes all units of a repository
|
||||
|
@ -19,7 +19,7 @@ type RepoUnit struct {
|
|||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type UnitType `xorm:"INDEX(s)"`
|
||||
Config core.Conversion `xorm:"TEXT"`
|
||||
Config convert.Conversion `xorm:"TEXT"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"`
|
||||
}
|
||||
|
||||
|
|
|
@ -524,7 +524,7 @@ func AddPublicKey(ownerID int64, name, content string, loginSourceID int64) (*Pu
|
|||
func GetPublicKeyByID(keyID int64) (*PublicKey, error) {
|
||||
key := new(PublicKey)
|
||||
has, err := x.
|
||||
Id(keyID).
|
||||
ID(keyID).
|
||||
Get(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"gopkg.in/testfixtures.v2"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
var fixtures *testfixtures.Context
|
||||
|
@ -36,7 +37,7 @@ func LoadFixtures() error {
|
|||
fmt.Printf("LoadFixtures failed after retries: %v\n", err)
|
||||
}
|
||||
// Now if we're running postgres we need to tell it to update the sequences
|
||||
if x.Dialect().DriverName() == "postgres" {
|
||||
if x.Dialect().URI().DBType == schemas.POSTGRES {
|
||||
results, err := x.QueryString(`SELECT 'SELECT SETVAL(' ||
|
||||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
|
||||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/unknwon/com"
|
||||
"gopkg.in/testfixtures.v2"
|
||||
"xorm.io/core"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
||||
// NonexistentID an ID that will never exist
|
||||
|
@ -92,7 +92,7 @@ func CreateTestEngine(fixturesDir string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x.SetMapper(core.GonicMapper{})
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
if err = x.StoreEngine("InnoDB").Sync2(tables...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue