2023-02-14 05:41:45 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"GoWeb/app"
|
|
|
|
"GoWeb/database"
|
2023-02-18 00:55:27 +00:00
|
|
|
"time"
|
2023-02-14 05:41:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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",
|
2023-02-18 00:55:27 +00:00
|
|
|
CreatedAt: time.Now(),
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
}
|
|
|
|
err := database.Migrate(app, user)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-02-14 05:41:45 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 20:55:09 +00:00
|
|
|
session := Session{
|
2023-04-06 13:56:48 +00:00
|
|
|
Id: 1,
|
|
|
|
UserId: 1,
|
|
|
|
AuthToken: "migrate",
|
|
|
|
RememberMe: false,
|
|
|
|
CreatedAt: time.Now(),
|
2023-02-28 20:55:09 +00:00
|
|
|
}
|
|
|
|
err = database.Migrate(app, session)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-18 00:55:27 +00:00
|
|
|
return nil
|
2023-02-14 05:41:45 +00:00
|
|
|
}
|