database: Update database defaults and add country

This prevents errors when scanning the fields on the database
This commit is contained in:
Daniel López Guimaraes 2024-04-20 13:44:44 +01:00
parent 7aef2f1750
commit f4a4b2830b
No known key found for this signature in database
GPG Key ID: 6AC74DE3DEF050E0
4 changed files with 25 additions and 18 deletions

View File

@ -13,7 +13,7 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) (*types.List[*fri
persistentInfos.Type = friends_3ds_types.NewFriendPersistentInfo()
rows, err := database.Postgres.Query(`
SELECT pid, region, area, language, favorite_title, favorite_title_version, comment, comment_changed, last_online, mii_changed FROM "3ds".user_data WHERE pid=ANY($1::int[])`, pq.Array(pids))
SELECT pid, region, area, language, country, favorite_title, favorite_title_version, comment, comment_changed, last_online, mii_changed FROM "3ds".user_data WHERE pid=ANY($1::int[])`, pq.Array(pids))
if err != nil {
return persistentInfos, err
}
@ -28,6 +28,7 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) (*types.List[*fri
var region uint8
var area uint8
var language uint8
var country uint8
var titleID uint64
var titleVersion uint16
var message string
@ -37,11 +38,12 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) (*types.List[*fri
// * This is allowed to error for now.
// * Some of these fields are optional, and the DB doesn't have defaults
rows.Scan(
err := rows.Scan(
&pid,
&region,
&area,
&language,
&country,
&titleID,
&titleVersion,
&message,
@ -49,13 +51,16 @@ func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) (*types.List[*fri
&lastOnlineTime,
&miiModifiedAtTime,
)
if err != nil {
return persistentInfos, err
}
gameKey.TitleID = types.NewPrimitiveU64(titleID)
gameKey.TitleVersion = types.NewPrimitiveU16(titleVersion)
persistentInfo.PID = types.NewPID(uint64(pid))
persistentInfo.Region = types.NewPrimitiveU8(region)
persistentInfo.Country = types.NewPrimitiveU8(0) // TODO - What is this?
persistentInfo.Country = types.NewPrimitiveU8(country)
persistentInfo.Area = types.NewPrimitiveU8(area)
persistentInfo.Language = types.NewPrimitiveU8(language)
persistentInfo.Platform = types.NewPrimitiveU8(2) // * Always 3DS

View File

@ -8,13 +8,14 @@ import (
// UpdateUserProfile updates a user's profile
func UpdateUserProfile(pid uint32, profileData *friends_3ds_types.MyProfile) error {
_, err := database.Postgres.Exec(`
INSERT INTO "3ds".user_data (pid, region, area, language)
VALUES ($1, $2, $3, $4)
INSERT INTO "3ds".user_data (pid, region, area, language, country)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (pid)
DO UPDATE SET
region = $2,
area = $3,
language = $4`, pid, profileData.Region.Value, profileData.Area.Value, profileData.Language.Value)
language = $4,
country = $5`, pid, profileData.Region.Value, profileData.Area.Value, profileData.Language.Value, profileData.Country.Value)
if err != nil {
return err

View File

@ -17,17 +17,18 @@ func initPostgres3DS() {
pid integer PRIMARY KEY,
show_online boolean DEFAULT true,
show_current_game boolean DEFAULT true,
comment text,
comment_changed bigint,
last_online bigint,
favorite_title bigint,
favorite_title_version integer,
mii_name text,
mii_data bytea,
mii_changed bigint,
region integer,
area integer,
language integer
comment text DEFAULT '',
comment_changed bigint DEFAULT 0,
last_online bigint DEFAULT 0,
favorite_title bigint DEFAULT 0,
favorite_title_version integer DEFAULT 0,
mii_name text DEFAULT '',
mii_data bytea DEFAULT '',
mii_changed bigint DEFAULT 0,
region integer DEFAULT 0,
area integer DEFAULT 0,
language integer DEFAULT 0,
country integer DEFAULT 0
)`)
if err != nil {
globals.Logger.Critical(err.Error())

View File

@ -20,7 +20,7 @@ func initPostgresWiiU() {
block_friend_requests boolean DEFAULT false,
comment text DEFAULT '',
comment_changed bigint DEFAULT 0,
last_online bigint
last_online bigint DEFAULT 0
)`)
if err != nil {
globals.Logger.Critical(err.Error())