You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
480 B
34 lines
480 B
3 months ago
|
package entities
|
||
|
|
||
|
import (
|
||
|
"encoding/gob"
|
||
|
"log"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
func Init(db *gorm.DB) error {
|
||
|
err := db.AutoMigrate(
|
||
|
&User{},
|
||
|
&Project{},
|
||
|
&Build{},
|
||
|
&BuildStep{},
|
||
|
)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
err = db.Model(&User{}).FirstOrCreate(&User{
|
||
|
ID: 1,
|
||
|
Username: "admin",
|
||
|
RawPassword: "111111",
|
||
|
}, User{ID: 1}).Error
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
|
||
|
// 使用 github.com/gorilla/sessions 需要
|
||
|
gob.Register(&User{})
|
||
|
|
||
|
return nil
|
||
|
}
|