Migration implementation, auto migrate when starting program

This commit is contained in:
Maximilian
2023-02-13 23:41:45 -06:00
parent bbbf14bdc7
commit fcd6477ec3
3 changed files with 135 additions and 1 deletions

21
models/migrations.go Normal file
View File

@ -0,0 +1,21 @@
package models
import (
"GoWeb/app"
"GoWeb/database"
)
// 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",
AuthToken: "migrate",
CreatedAt: "2021-01-01 00:00:00",
UpdatedAt: "2021-01-01 00:00:00",
}
return database.Migrate(app, user)
}