2019-11-15 03:03:56 +00:00
|
|
|
package models
|
|
|
|
|
2020-02-18 02:10:35 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
)
|
2019-11-15 03:03:56 +00:00
|
|
|
|
|
|
|
// DB is the database handle for all the models.
|
|
|
|
var DB *gorm.DB
|
|
|
|
|
2020-02-18 02:10:35 +00:00
|
|
|
// BaseModel is the base column set for all models.
|
|
|
|
type BaseModel struct {
|
|
|
|
ID int `gorm:"primary_key"`
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:03:56 +00:00
|
|
|
// UseDB registers a database driver.
|
|
|
|
func UseDB(db *gorm.DB) {
|
|
|
|
DB = db
|
|
|
|
DB.AutoMigrate(&User{})
|
2020-02-18 02:10:35 +00:00
|
|
|
DB.Debug().AutoMigrate(&Post{})
|
2019-11-27 00:54:02 +00:00
|
|
|
DB.AutoMigrate(&TaggedPost{})
|
2020-02-14 06:03:01 +00:00
|
|
|
DB.AutoMigrate(&Comment{})
|
2019-11-15 03:03:56 +00:00
|
|
|
}
|