Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes point calculations from bad migration for 1.20.1 #767

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const default_theme_light = JSON.stringify({
},
});
// Used to tell the program what version the database should get to
const currentVersion = "1.20.1";
const currentVersion = "1.20.2";
// Creates the default config
async function createConfig() {
const connection = await connect();
Expand Down
24 changes: 20 additions & 4 deletions scripts/upgradeDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,11 @@ export default async function main(oldVersion: string): Promise<string> {
e.matchday,
],
);
await connection.query(
"UPDATE leagueUsers SET predictionPoints=predictionPoints+?, points=points+? WHERE leagueID=?",
[predictionPoints - e.predictionPoints, e.leagueID],
);
// Bad query is removed and is fixed in the 1.20.2 update
// await connection.query(
// "UPDATE leagueUsers SET predictionPoints=predictionPoints+?, points=points+? WHERE leagueID=?",
// [predictionPoints - e.predictionPoints, e.leagueID],
// );
}
res();
}),
Expand All @@ -756,6 +757,21 @@ export default async function main(oldVersion: string): Promise<string> {
oldVersion = "1.20.1";
console.log("Upgraded database to version 1.20.1");
}
if (oldVersion === "1.20.1") {
console.log("Upgrading database to version 1.20.2");
// Fixes point totals in tables
await connection.query(
"UPDATE points SET points=fantasyPoints+predictionPoints",
);
await connection.query(
"UPDATE leagueUsers SET predictionPoints=(SELECT SUM(predictionPoints) FROM points WHERE leagueUsers.user=points.user AND leagueUsers.leagueID=points.leagueID)",
);
await connection.query(
"UPDATE leagueUsers SET points=predictionPoints+fantasyPoints;",
);
oldVersion = "1.20.2";
console.log("Upgraded database to version 1.20.2");
}
connection.end();
return oldVersion;
}