ADD: added function to update db scheme automaticly
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user