switch from searching and updating database with playerName, because playername can change, but the playerid usually won't
This commit is contained in:
parent
d46a516b79
commit
b0f47d19e2
|
@ -47,6 +47,7 @@ export async function action({ request }) {
|
|||
update: {
|
||||
players: {
|
||||
create: {
|
||||
playerId: parseInt(me.id),
|
||||
playerName: me.username,
|
||||
rank: me.statistics.global_rank
|
||||
? parseInt(me.statistics.global_rank)
|
||||
|
@ -65,6 +66,7 @@ export async function action({ request }) {
|
|||
name: county,
|
||||
players: {
|
||||
create: {
|
||||
playerId: parseInt(me.id),
|
||||
playerName: me.username,
|
||||
rank: me.statistics.global_rank
|
||||
? parseInt(me.statistics.global_rank)
|
||||
|
@ -101,7 +103,7 @@ export async function loader({ request }) {
|
|||
|
||||
const selfData = await prisma.player.findUnique({
|
||||
where: {
|
||||
playerName: me.username,
|
||||
playerId: parseInt(me.id),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -12,9 +12,10 @@ export async function loader({ request }) {
|
|||
|
||||
const updateUser = await prisma.player.update({
|
||||
where: {
|
||||
playerName: me.username,
|
||||
playerId: me.id,
|
||||
},
|
||||
data: {
|
||||
playerId: me.id,
|
||||
playerName: me.username,
|
||||
rank: me.statistics.global_rank
|
||||
? parseInt(me.statistics.global_rank)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `playerId` to the `Player` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Player" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"playerId" INTEGER NOT NULL,
|
||||
"playerName" TEXT NOT NULL,
|
||||
"rank" INTEGER,
|
||||
"SSranks" INTEGER,
|
||||
"Sranks" INTEGER,
|
||||
"Aranks" INTEGER,
|
||||
"countyId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Player_countyId_fkey" FOREIGN KEY ("countyId") REFERENCES "County" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Player" ("Aranks", "SSranks", "Sranks", "countyId", "id", "playerName", "rank") SELECT "Aranks", "SSranks", "Sranks", "countyId", "id", "playerName", "rank" FROM "Player";
|
||||
DROP TABLE "Player";
|
||||
ALTER TABLE "new_Player" RENAME TO "Player";
|
||||
CREATE UNIQUE INDEX "Player_playerId_key" ON "Player"("playerId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
|
@ -18,7 +18,8 @@ model County {
|
|||
|
||||
model Player {
|
||||
id Int @id @default(autoincrement())
|
||||
playerName String @unique
|
||||
playerId Int @unique
|
||||
playerName String
|
||||
rank Int?
|
||||
SSranks Int?
|
||||
Sranks Int?
|
||||
|
|
Loading…
Reference in New Issue