GoWeb/models/migrations.go

38 lines
801 B
Go
Raw Permalink Normal View History

package models
import (
"GoWeb/app"
"GoWeb/database"
"time"
)
// RunAllMigrations defines the structs that should be represented in the database
func RunAllMigrations(app *app.App) error {
// Declare new dummy user for reflection
user := User{
Id: 1, // Id is handled automatically, but it is added here to show it will be skipped during column creation
Username: "migrate",
Password: "migrate",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
err := database.Migrate(app, user)
if err != nil {
return err
}
2023-02-28 20:55:09 +00:00
session := Session{
Id: 1,
UserId: 1,
AuthToken: "migrate",
2024-02-14 19:16:15 +00:00
RememberMe: true, // Booleans must be true to migrate properly
CreatedAt: time.Now(),
2023-02-28 20:55:09 +00:00
}
err = database.Migrate(app, session)
if err != nil {
return err
}
return nil
}