ADD: added function to update db scheme automaticly

This commit is contained in:
hwinkel
2025-11-18 22:23:08 +01:00
parent ef396af480
commit 3818fbf460
15 changed files with 876 additions and 186 deletions

View File

@@ -39,22 +39,25 @@ func CheckIfTablesExist(db *sql.DB) (bool, error) {
return true, nil // All tables exist
}
func tableExists(db *sql.DB, tableName string) (bool, error) {
query := `
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = $1
);
`
var exists bool
err := db.QueryRow(query, tableName).Scan(&exists)
return exists, err
}
// func tableExists(db *sql.DB, tableName string) (bool, error) {
// query := `
// SELECT EXISTS (
// SELECT FROM information_schema.tables
// WHERE table_schema = 'public' AND table_name = $1
// );
// `
// var exists bool
// err := db.QueryRow(query, tableName).Scan(&exists)
// return exists, err
// }
func InitTables(d *sql.DB) error {
CreateOrUpdateTablePG(d, "users", player.User{})
CreateOrUpdateTablePG(d, "roles", player.Roles{})
tables := []string{
player.PlayerTable,
player.RoleTable,
// player.PlayerTable,
// player.RoleTable,
teamTable,
}