From f3be1a3d7b9f0e51ec4aecb8f20ec5f621670cc4 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Tue, 11 Jan 2022 11:31:45 -0800 Subject: [PATCH] adding accounts for automigration --- net/server/internal/routers.go | 3 +++ net/server/internal/store/db_schema.go | 29 ++++++++++++++++++++++++++ net/server/main.go | 3 +++ 3 files changed, 35 insertions(+) create mode 100644 net/server/internal/store/db_schema.go diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index e3bacb0d..7a2281e5 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -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 diff --git a/net/server/internal/store/db_schema.go b/net/server/internal/store/db_schema.go new file mode 100644 index 00000000..b5c4ba92 --- /dev/null +++ b/net/server/internal/store/db_schema.go @@ -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 +} + diff --git a/net/server/main.go b/net/server/main.go index 8c18653f..35d56564 100644 --- a/net/server/main.go +++ b/net/server/main.go @@ -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)