@@ -89,7 +89,7 @@ func RecreateTable(sess *xorm.Session, bean interface{}) error {
89
89
hasID = hasID || (column .IsPrimaryKey && column .IsAutoIncrement )
90
90
}
91
91
92
- if hasID && setting .Database .UseMSSQL {
92
+ if hasID && setting .Database .Type . IsMSSQL () {
93
93
if _ , err := sess .Exec (fmt .Sprintf ("SET IDENTITY_INSERT `%s` ON" , tempTableName )); err != nil {
94
94
log .Error ("Unable to set identity insert for table %s. Error: %v" , tempTableName , err )
95
95
return err
@@ -143,15 +143,15 @@ func RecreateTable(sess *xorm.Session, bean interface{}) error {
143
143
return err
144
144
}
145
145
146
- if hasID && setting .Database .UseMSSQL {
146
+ if hasID && setting .Database .Type . IsMSSQL () {
147
147
if _ , err := sess .Exec (fmt .Sprintf ("SET IDENTITY_INSERT `%s` OFF" , tempTableName )); err != nil {
148
148
log .Error ("Unable to switch off identity insert for table %s. Error: %v" , tempTableName , err )
149
149
return err
150
150
}
151
151
}
152
152
153
153
switch {
154
- case setting .Database .UseSQLite3 :
154
+ case setting .Database .Type . IsSQLite3 () :
155
155
// SQLite will drop all the constraints on the old table
156
156
if _ , err := sess .Exec (fmt .Sprintf ("DROP TABLE `%s`" , tableName )); err != nil {
157
157
log .Error ("Unable to drop old table %s. Error: %v" , tableName , err )
@@ -178,7 +178,7 @@ func RecreateTable(sess *xorm.Session, bean interface{}) error {
178
178
return err
179
179
}
180
180
181
- case setting .Database .UseMySQL :
181
+ case setting .Database .Type . IsMySQL () :
182
182
// MySQL will drop all the constraints on the old table
183
183
if _ , err := sess .Exec (fmt .Sprintf ("DROP TABLE `%s`" , tableName )); err != nil {
184
184
log .Error ("Unable to drop old table %s. Error: %v" , tableName , err )
@@ -205,7 +205,7 @@ func RecreateTable(sess *xorm.Session, bean interface{}) error {
205
205
log .Error ("Unable to recreate uniques on table %s. Error: %v" , tableName , err )
206
206
return err
207
207
}
208
- case setting .Database .UsePostgreSQL :
208
+ case setting .Database .Type . IsPostgreSQL () :
209
209
var originalSequences []string
210
210
type sequenceData struct {
211
211
LastValue int `xorm:"'last_value'"`
@@ -296,7 +296,7 @@ func RecreateTable(sess *xorm.Session, bean interface{}) error {
296
296
297
297
}
298
298
299
- case setting .Database .UseMSSQL :
299
+ case setting .Database .Type . IsMSSQL () :
300
300
// MSSQL will drop all the constraints on the old table
301
301
if _ , err := sess .Exec (fmt .Sprintf ("DROP TABLE `%s`" , tableName )); err != nil {
302
302
log .Error ("Unable to drop old table %s. Error: %v" , tableName , err )
@@ -323,7 +323,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
323
323
// TODO: This will not work if there are foreign keys
324
324
325
325
switch {
326
- case setting .Database .UseSQLite3 :
326
+ case setting .Database .Type . IsSQLite3 () :
327
327
// First drop the indexes on the columns
328
328
res , errIndex := sess .Query (fmt .Sprintf ("PRAGMA index_list(`%s`)" , tableName ))
329
329
if errIndex != nil {
@@ -405,7 +405,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
405
405
return err
406
406
}
407
407
408
- case setting .Database .UsePostgreSQL :
408
+ case setting .Database .Type . IsPostgreSQL () :
409
409
cols := ""
410
410
for _ , col := range columnNames {
411
411
if cols != "" {
@@ -416,7 +416,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
416
416
if _ , err := sess .Exec (fmt .Sprintf ("ALTER TABLE `%s` %s" , tableName , cols )); err != nil {
417
417
return fmt .Errorf ("Drop table `%s` columns %v: %v" , tableName , columnNames , err )
418
418
}
419
- case setting .Database .UseMySQL :
419
+ case setting .Database .Type . IsMySQL () :
420
420
// Drop indexes on columns first
421
421
sql := fmt .Sprintf ("SHOW INDEX FROM %s WHERE column_name IN ('%s')" , tableName , strings .Join (columnNames , "','" ))
422
422
res , err := sess .Query (sql )
@@ -444,7 +444,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
444
444
if _ , err := sess .Exec (fmt .Sprintf ("ALTER TABLE `%s` %s" , tableName , cols )); err != nil {
445
445
return fmt .Errorf ("Drop table `%s` columns %v: %v" , tableName , columnNames , err )
446
446
}
447
- case setting .Database .UseMSSQL :
447
+ case setting .Database .Type . IsMSSQL () :
448
448
cols := ""
449
449
for _ , col := range columnNames {
450
450
if cols != "" {
@@ -543,13 +543,13 @@ func newXORMEngine() (*xorm.Engine, error) {
543
543
544
544
func deleteDB () error {
545
545
switch {
546
- case setting .Database .UseSQLite3 :
546
+ case setting .Database .Type . IsSQLite3 () :
547
547
if err := util .Remove (setting .Database .Path ); err != nil {
548
548
return err
549
549
}
550
550
return os .MkdirAll (path .Dir (setting .Database .Path ), os .ModePerm )
551
551
552
- case setting .Database .UseMySQL :
552
+ case setting .Database .Type . IsMySQL () :
553
553
db , err := sql .Open ("mysql" , fmt .Sprintf ("%s:%s@tcp(%s)/" ,
554
554
setting .Database .User , setting .Database .Passwd , setting .Database .Host ))
555
555
if err != nil {
@@ -565,7 +565,7 @@ func deleteDB() error {
565
565
return err
566
566
}
567
567
return nil
568
- case setting .Database .UsePostgreSQL :
568
+ case setting .Database .Type . IsPostgreSQL () :
569
569
db , err := sql .Open ("postgres" , fmt .Sprintf ("postgres://%s:%s@%s/?sslmode=%s" ,
570
570
setting .Database .User , setting .Database .Passwd , setting .Database .Host , setting .Database .SSLMode ))
571
571
if err != nil {
@@ -612,7 +612,7 @@ func deleteDB() error {
612
612
}
613
613
return nil
614
614
}
615
- case setting .Database .UseMSSQL :
615
+ case setting .Database .Type . IsMSSQL () :
616
616
host , port := setting .ParseMSSQLHostPort (setting .Database .Host )
617
617
db , err := sql .Open ("mssql" , fmt .Sprintf ("server=%s; port=%s; database=%s; user id=%s; password=%s;" ,
618
618
host , port , "master" , setting .Database .User , setting .Database .Passwd ))
0 commit comments