mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Drop some unused columns, make TournamentRounds.maps always to be defined
This commit is contained in:
parent
9cd3beca4d
commit
12590ba0df
|
|
@ -131,12 +131,6 @@ export interface BuildWeapon {
|
|||
weaponSplId: MainWeaponId;
|
||||
}
|
||||
|
||||
/** Image associated with the avatar when the event is showcased on the front page */
|
||||
export type CalendarEventAvatarMetadata = {
|
||||
backgroundColor: string;
|
||||
textColor: string;
|
||||
};
|
||||
|
||||
export type CalendarEventTag = keyof typeof tags;
|
||||
|
||||
export interface CalendarEvent {
|
||||
|
|
@ -153,8 +147,6 @@ export interface CalendarEvent {
|
|||
tournamentId: number | null;
|
||||
organizationId: number | null;
|
||||
avatarImgId: number | null;
|
||||
// TODO: remove in migration
|
||||
avatarMetadata: JSONColumnTypeNullable<CalendarEventAvatarMetadata>;
|
||||
}
|
||||
|
||||
export interface CalendarEventBadge {
|
||||
|
|
@ -537,8 +529,6 @@ export const TournamentMatchStatus = {
|
|||
};
|
||||
|
||||
export interface TournamentMatch {
|
||||
// TODO: remove
|
||||
bestOf: Generated<3 | 5 | 7>;
|
||||
chatCode: string | null;
|
||||
groupId: number;
|
||||
id: GeneratedAlways<number>;
|
||||
|
|
@ -620,7 +610,7 @@ export interface TournamentRound {
|
|||
id: GeneratedAlways<number>;
|
||||
number: number;
|
||||
stageId: number;
|
||||
maps: JSONColumnTypeNullable<TournamentRoundMaps>;
|
||||
maps: JSONColumnType<TournamentRoundMaps>;
|
||||
}
|
||||
|
||||
// when updating this also update `defaultBracketSettings` in tournament-utils.ts
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|||
"TournamentMatch.opponentOne",
|
||||
"TournamentMatch.opponentTwo",
|
||||
"Tournament.mapPickingStyle",
|
||||
"TournamentMatch.bestOf",
|
||||
"TournamentRound.maps",
|
||||
jsonArrayFrom(
|
||||
eb
|
||||
|
|
@ -122,7 +121,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|||
: [];
|
||||
|
||||
return resolveMapList({
|
||||
bestOf: match.bestOf,
|
||||
tournamentId: match.tournamentId,
|
||||
matchId: id,
|
||||
teams: [match.opponentOne.id, match.opponentTwo.id],
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ export const action: ActionFunction = async ({ params, request }) => {
|
|||
const mapList =
|
||||
match.opponentOne?.id && match.opponentTwo?.id
|
||||
? resolveMapList({
|
||||
bestOf: match.bestOf,
|
||||
tournamentId,
|
||||
matchId,
|
||||
teams: [match.opponentOne.id, match.opponentTwo.id],
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ export function MatchActions({
|
|||
scores[1] + (winnerId === teams[1].id ? 1 : 0),
|
||||
];
|
||||
const wouldEndSet = isSetOverByScore({
|
||||
count: data.match.roundMaps?.count ?? data.match.bestOf,
|
||||
count: data.match.roundMaps.count,
|
||||
countType: data.match.roundMaps?.type ?? "BEST_OF",
|
||||
scores: newScore,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,11 +21,9 @@ import type { Bracket } from "./Bracket";
|
|||
interface ResolveCurrentMapListArgs {
|
||||
tournamentId: number;
|
||||
mapPickingStyle: Tables["Tournament"]["mapPickingStyle"];
|
||||
/** @deprecated use maps.count instead */
|
||||
bestOf: 3 | 5 | 7;
|
||||
matchId: number;
|
||||
teams: [teamOneId: number, teamTwoId: number];
|
||||
maps: TournamentRoundMaps | null;
|
||||
maps: TournamentRoundMaps;
|
||||
pickBanEvents: Array<{
|
||||
mode: ModeShort;
|
||||
stageId: StageId;
|
||||
|
|
@ -120,8 +118,6 @@ export function resolveFreshTeamPickedMapList(
|
|||
};
|
||||
|
||||
const count = () => {
|
||||
if (!args.maps?.count) return args.bestOf;
|
||||
|
||||
if (args.maps.pickBan) {
|
||||
return pickBanCount(args.maps.pickBan, args.maps.count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|||
const mapList =
|
||||
match.opponentOne?.id && match.opponentTwo?.id
|
||||
? resolveMapList({
|
||||
bestOf: match.bestOf,
|
||||
tournamentId,
|
||||
matchId,
|
||||
teams: [match.opponentOne.id, match.opponentTwo.id],
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { sql } from "~/db/sql";
|
||||
import type { Tables } from "~/db/tables";
|
||||
|
||||
const stm = sql.prepare(/* sql */ `
|
||||
select
|
||||
"TournamentRound"."id" as "roundId",
|
||||
"TournamentMatch"."bestOf"
|
||||
from "TournamentRound"
|
||||
left join "TournamentMatch" on "TournamentRound"."id" = "TournamentMatch"."roundId"
|
||||
left join "TournamentStage" on "TournamentRound"."stageId" = "TournamentStage"."id"
|
||||
where "TournamentStage"."tournamentId" = @tournamentId
|
||||
group by "TournamentRound"."id"
|
||||
`);
|
||||
|
||||
interface BestOfByTournamentId {
|
||||
roundId: Tables["TournamentRound"]["id"];
|
||||
bestOf: Tables["TournamentMatch"]["bestOf"];
|
||||
}
|
||||
|
||||
export function bestOfsByTournamentId(tournamentId: number) {
|
||||
return stm.all({ tournamentId }) as BestOfByTournamentId[];
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ const stm = sql.prepare(/* sql */ `
|
|||
"TournamentMatch"."groupId",
|
||||
"TournamentMatch"."opponentOne",
|
||||
"TournamentMatch"."opponentTwo",
|
||||
"TournamentMatch"."bestOf",
|
||||
"TournamentMatch"."chatCode",
|
||||
"Tournament"."mapPickingStyle",
|
||||
"TournamentRound"."id" as "roundId",
|
||||
|
|
@ -50,27 +49,22 @@ export type FindMatchById = ReturnType<typeof findMatchById>;
|
|||
|
||||
export const findMatchById = (id: number) => {
|
||||
const row = stm.get({ id }) as
|
||||
| ((Pick<
|
||||
Tables["TournamentMatch"],
|
||||
"id" | "groupId" | "bestOf" | "chatCode"
|
||||
> &
|
||||
| ((Pick<Tables["TournamentMatch"], "id" | "groupId" | "chatCode"> &
|
||||
Pick<Tables["Tournament"], "mapPickingStyle"> & { players: string }) & {
|
||||
opponentOne: string;
|
||||
opponentTwo: string;
|
||||
roundId: number;
|
||||
roundMaps: string | null;
|
||||
roundMaps: string;
|
||||
})
|
||||
| undefined;
|
||||
|
||||
if (!row) return;
|
||||
|
||||
const roundMaps = row.roundMaps
|
||||
? (JSON.parse(row.roundMaps) as TournamentRoundMaps)
|
||||
: null;
|
||||
const roundMaps = JSON.parse(row.roundMaps) as TournamentRoundMaps;
|
||||
|
||||
return {
|
||||
...row,
|
||||
bestOf: (roundMaps?.count ?? row.bestOf) as 3 | 5 | 7,
|
||||
bestOf: roundMaps.count,
|
||||
roundId: row.roundId,
|
||||
roundMaps,
|
||||
opponentOne: JSON.parse(row.opponentOne) as Match["opponent1"],
|
||||
|
|
|
|||
|
|
@ -1095,7 +1095,7 @@ export function resetBracket(tournamentStageId: number) {
|
|||
|
||||
export type TournamentRepositoryInsertableMatch = Omit<
|
||||
Insertable<DB["TournamentMatch"]>,
|
||||
"status" | "bestOf" | "chatCode"
|
||||
"status" | "chatCode"
|
||||
>;
|
||||
|
||||
export function insertSwissMatches(
|
||||
|
|
|
|||
35
migrations/095-drop-unused-tournament-columns.js
Normal file
35
migrations/095-drop-unused-tournament-columns.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
export function up(db) {
|
||||
db.transaction(() => {
|
||||
const roundsWithNullMaps = db
|
||||
.prepare(
|
||||
/* sql */ `select "id" from "TournamentRound" where "maps" is null`,
|
||||
)
|
||||
.all()
|
||||
.map((row) => row.id);
|
||||
|
||||
for (const roundId of roundsWithNullMaps) {
|
||||
const count = db
|
||||
.prepare(
|
||||
/* sql */ `select "bestOf" from "TournamentMatch" where "roundId" = @roundId`,
|
||||
)
|
||||
.get({ roundId }).bestOf;
|
||||
|
||||
db.prepare(
|
||||
/* sql */ `update "TournamentRound" set "maps" = @maps where "id" = @id`,
|
||||
).run({
|
||||
id: roundId,
|
||||
maps: JSON.stringify({
|
||||
type: "BEST_OF",
|
||||
count,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
db.prepare(
|
||||
/* sql */ `alter table "TournamentMatch" drop column "bestOf"`,
|
||||
).run();
|
||||
db.prepare(
|
||||
/* sql */ `alter table "CalendarEvent" drop column "avatarMetadata"`,
|
||||
).run();
|
||||
})();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user