update schema to merge existing data, move trophy

This commit is contained in:
wish
2022-09-04 18:12:51 +10:00
parent 377bb39be6
commit 670f8f7882
2 changed files with 22 additions and 12 deletions

View File

@@ -13,7 +13,25 @@ CREATE TABLE IF NOT EXISTS public.user_binary
bookshelf bytea, bookshelf bytea,
gallery bytea, gallery bytea,
tore bytea, tore bytea,
garden bytea garden bytea,
mission bytea
); );
-- Create entries for existing users
INSERT INTO public.user_binary (id) SELECT c.id FROM characters c;
-- Copy existing data
UPDATE public.user_binary
SET house_furniture = (SELECT house FROM characters WHERE user_binary.id = characters.id);
UPDATE public.user_binary
SET mission = (SELECT trophy FROM characters WHERE user_binary.id = characters.id);
-- Drop old data location
ALTER TABLE public.characters
DROP COLUMN house;
ALTER TABLE public.characters
DROP COLUMN trophy;
END; END;

View File

@@ -189,26 +189,18 @@ func handleMsgMhfLoadHouse(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfGetMyhouseInfo(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfGetMyhouseInfo(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetMyhouseInfo) pkt := p.(*mhfpacket.MsgMhfGetMyhouseInfo)
var data []byte var data []byte
err := s.server.db.QueryRow("SELECT trophy FROM characters WHERE id = $1", s.charID).Scan(&data) s.server.db.QueryRow(`SELECT mission FROM user_binary WHERE id=$1`, s.charID).Scan(&data)
if err != nil {
panic(err)
}
if len(data) > 0 { if len(data) > 0 {
doAckBufSucceed(s, pkt.AckHandle, data) doAckBufSucceed(s, pkt.AckHandle, data)
} else { } else {
doAckBufSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) doAckBufSucceed(s, pkt.AckHandle, make([]byte, 9))
} }
} }
func handleMsgMhfUpdateMyhouseInfo(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfUpdateMyhouseInfo(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfUpdateMyhouseInfo) pkt := p.(*mhfpacket.MsgMhfUpdateMyhouseInfo)
s.server.db.Exec("UPDATE user_binary SET mission=$1 WHERE id=$2", pkt.Unk0, s.charID)
_, err := s.server.db.Exec("UPDATE characters SET trophy=$1 WHERE id=$2", pkt.Unk0, s.charID)
if err != nil {
panic(err)
}
doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00}) doAckSimpleSucceed(s, pkt.AckHandle, []byte{0x00, 0x00, 0x00, 0x00})
} }