|
|
|
@ -19,6 +19,8 @@ import ( |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
orm *xorm.Engine |
|
|
|
|
tables []interface{} |
|
|
|
|
|
|
|
|
|
HasEngine bool |
|
|
|
|
|
|
|
|
|
DbCfg struct { |
|
|
|
@ -28,6 +30,11 @@ var ( |
|
|
|
|
UseSQLite3 bool |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch), |
|
|
|
|
new(Action), new(Access), new(Issue), new(Comment)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func LoadModelsConfig() { |
|
|
|
|
DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") |
|
|
|
|
if DbCfg.Type == "sqlite3" { |
|
|
|
@ -58,9 +65,7 @@ func NewTestEngine(x *xorm.Engine) (err error) { |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("models.init(fail to conntect database): %v\n", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch), |
|
|
|
|
new(Action), new(Access), new(Issue), new(Comment)) |
|
|
|
|
return x.Sync(tables...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func SetEngine() (err error) { |
|
|
|
@ -102,8 +107,8 @@ func SetEngine() (err error) { |
|
|
|
|
func NewEngine() (err error) { |
|
|
|
|
if err = SetEngine(); err != nil { |
|
|
|
|
return err |
|
|
|
|
} else if err = orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), |
|
|
|
|
new(Action), new(Access), new(Issue), new(Comment)); err != nil { |
|
|
|
|
} |
|
|
|
|
if err = orm.Sync(tables...); err != nil { |
|
|
|
|
return fmt.Errorf("sync database struct error: %v\n", err) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|