2025-04-24 13:58:05 -05:00
|
|
|
package databasecommands
|
2025-04-21 23:05:50 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2025-04-28 12:38:15 -05:00
|
|
|
character "example.com/database/character"
|
|
|
|
customization "example.com/database/customization"
|
2025-04-27 23:14:37 -05:00
|
|
|
function "example.com/database/function"
|
2025-04-28 12:38:15 -05:00
|
|
|
functionset "example.com/database/functionset"
|
2025-04-27 23:14:37 -05:00
|
|
|
functiontag "example.com/database/functiontag"
|
|
|
|
group "example.com/database/group"
|
2025-04-28 12:38:15 -05:00
|
|
|
inventoryslot "example.com/database/inventoryslot"
|
|
|
|
item "example.com/database/item"
|
|
|
|
itemtag "example.com/database/itemtag"
|
|
|
|
person "example.com/database/person"
|
|
|
|
role "example.com/database/role"
|
|
|
|
schematic "example.com/database/schematic"
|
|
|
|
tier "example.com/database/tier"
|
|
|
|
user "example.com/database/user"
|
2025-04-24 13:58:05 -05:00
|
|
|
|
2025-04-21 23:05:50 -05:00
|
|
|
"gorm.io/driver/sqlite"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitializeDatabase() *gorm.DB {
|
2025-04-24 13:58:05 -05:00
|
|
|
db, err := gorm.Open(sqlite.Open("../db/main.db"), &gorm.Config{})
|
2025-04-21 23:05:50 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Failed to connect to database.")
|
|
|
|
}
|
2025-04-25 17:39:40 -05:00
|
|
|
db.AutoMigrate(
|
2025-04-28 12:38:15 -05:00
|
|
|
&user.User{},
|
2025-04-27 23:14:37 -05:00
|
|
|
&group.Group{},
|
|
|
|
&functiontag.FunctionTag{},
|
2025-04-28 12:38:15 -05:00
|
|
|
&itemtag.ItemTag{},
|
2025-04-27 23:14:37 -05:00
|
|
|
&function.Function{},
|
2025-04-28 12:38:15 -05:00
|
|
|
&functionset.FunctionSet{},
|
|
|
|
&tier.Tier{},
|
|
|
|
&role.Role{},
|
|
|
|
&person.Person{},
|
|
|
|
&item.Item{},
|
|
|
|
&inventoryslot.InventorySlot{},
|
|
|
|
&character.Character{},
|
|
|
|
&customization.Customization{},
|
|
|
|
&schematic.Schematic{},
|
2025-04-25 17:39:40 -05:00
|
|
|
)
|
2025-04-21 23:05:50 -05:00
|
|
|
return db
|
|
|
|
}
|
2025-04-22 16:21:40 -05:00
|
|
|
|
2025-04-25 17:39:40 -05:00
|
|
|
func LogoutDatabaseUser(db *gorm.DB, oauthToken string) {
|
2025-04-28 12:38:15 -05:00
|
|
|
db.Model(&user.User{}).Where("login_token = ?", oauthToken).Update("logged_in", false)
|
2025-04-25 17:39:40 -05:00
|
|
|
}
|