adding accounts for automigration

This commit is contained in:
Roland Osborne 2022-01-11 11:31:45 -08:00
parent 951363bc04
commit f3be1a3d7b
3 changed files with 35 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
"strings"
"gorm.io/gorm"
"github.com/gorilla/mux"
store "databag/internal/store"
)
type Route struct {
@ -27,6 +28,8 @@ type Route struct {
type Routes []Route
func NewRouter(db *gorm.DB) *mux.Router {
store.AutoMigrate(db);
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler

View File

@ -0,0 +1,29 @@
package store
import "gorm.io/gorm"
func AutoMigrate(db *gorm.DB) {
db.AutoMigrate(&Account{});
}
type Account struct {
ID uint `gorm:"primaryKey;not null;unique;autoIncrement"`
Did string `gorm:"not null"`
Username string `gorm:"not null"`
Password string `gorm:"not null"`
Salt string `gorm:"not null"`
Name string
Description string
Location string
Image string
Created int64 `gorm:"autoCreateTime"`
profileRevision uint64
contentRevision uint64
viewRevision uint64
groupRevision uint64
labelRevision uint64
cardRevision uint64
dialogueRevision uint64
insightRevision uint64
}

View File

@ -15,6 +15,7 @@ import (
"gorm.io/gorm"
"gorm.io/driver/sqlite"
app "databag/internal"
store "databag/internal/store"
)
func main() {
@ -23,6 +24,8 @@ func main() {
if err != nil {
panic("failed to connect database")
}
store.AutoMigrate(db);
log.Printf("Server started")
router := app.NewRouter(db)