gophertype/pkg/models/models.go
Noah 5b6712ea97 Blog Archive, RSS Feeds, and Model Cleanup
* Legacy-importer tool updates the DB primary key serial after migrating
  the posts, to be max(posts.id)+1 -- especially important for
  PostgreSQL and MySQL (SQLite3 correctly picked the next ID by
  default?)
* Add blog archive page and RSS, Atom and JSON feeds for the blog.
  URLs are /blog.rss, /blog.atom and /blog.json
2020-02-17 18:10:35 -08:00

27 lines
478 B
Go

package models
import (
"time"
"github.com/jinzhu/gorm"
)
// DB is the database handle for all the models.
var DB *gorm.DB
// BaseModel is the base column set for all models.
type BaseModel struct {
ID int `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
}
// UseDB registers a database driver.
func UseDB(db *gorm.DB) {
DB = db
DB.AutoMigrate(&User{})
DB.Debug().AutoMigrate(&Post{})
DB.AutoMigrate(&TaggedPost{})
DB.AutoMigrate(&Comment{})
}