mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding accounts for automigration
This commit is contained in:
parent
951363bc04
commit
f3be1a3d7b
@ -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
|
||||
|
29
net/server/internal/store/db_schema.go
Normal file
29
net/server/internal/store/db_schema.go
Normal 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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user