Switch from serial to UUID's

This commit is contained in:
Kalle (Sendou)
2021-11-30 21:34:00 +02:00
parent 414de74f3b
commit 357d4e03fd
8 changed files with 40 additions and 39 deletions

View File

@@ -41,10 +41,10 @@ export const action: ActionFunction = async ({
}): Promise<Response | ActionData> => {
const formData = await request.formData();
const teamName = formData.get("teamName");
const tournamentId = Number(formData.get("tournamentId"));
const tournamentId = formData.get("tournamentId");
invariant(typeof teamName === "string", "Invalid type for team name.");
invariant(
typeof tournamentId === "number",
typeof tournamentId === "string",
"Invalid type for tournament id."
);

View File

@@ -10,7 +10,7 @@ export default function TeamsTab() {
const sortedTeams = teams
// TODO: user id here
.sort(sortOwnTeamsAndFullTeamsFirst(-1))
.sort(sortOwnTeamsAndFullTeamsFirst(""))
.map((team) => {
return {
...team,
@@ -31,10 +31,10 @@ function sortCaptainFirst(a: { captain: boolean }, b: { captain: boolean }) {
return Number(b.captain) - Number(a.captain);
}
function sortOwnTeamsAndFullTeamsFirst(userId?: number) {
function sortOwnTeamsAndFullTeamsFirst(userId?: string) {
return function (
a: { members: { member: { id: number } }[] },
b: { members: { member: { id: number } }[] }
a: { members: { member: { id: string } }[] },
b: { members: { member: { id: string } }[] }
) {
if (userId) {
const aSortValue = Number(

View File

@@ -14,7 +14,7 @@ export async function findTournamentByNameForUrl({
}: {
organizationNameForUrl: string;
tournamentNameForUrl: string;
userId?: number;
userId?: string;
}) {
const tournaments = await db.tournament.findMany({
where: {
@@ -117,9 +117,9 @@ export function createTournamentTeam({
teamName,
tournamentId,
}: {
userId: number;
userId: string;
teamName: string;
tournamentId: number;
tournamentId: string;
}) {
return db.tournamentTeam.create({
data: {

View File

@@ -22,7 +22,7 @@ export const getUser = (ctx: any) => {
};
export type LoggedInUser = {
id: number;
id: string;
discordId: string;
discordAvatar: string;
} | null;

View File

@@ -16,6 +16,7 @@
"seed": "npx prisma db seed",
"seed:reset": "npx prisma migrate reset --force --skip-generate",
"lint:styles": "stylelint \"app/styles/**/*.css\"",
"typecheck": "tsc --noEmit",
"cy:open": "npx cypress open",
"cy:run": "npx cypress run"
},

View File

@@ -3,7 +3,7 @@ CREATE TYPE "Mode" AS ENUM ('TW', 'SZ', 'TC', 'RM', 'CB');
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"id" TEXT NOT NULL,
"discordId" TEXT NOT NULL,
"discordName" TEXT NOT NULL,
"discordDiscriminator" TEXT NOT NULL,
@@ -21,10 +21,10 @@ CREATE TABLE "User" (
-- CreateTable
CREATE TABLE "Organization" (
"id" SERIAL NOT NULL,
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"nameForUrl" TEXT NOT NULL,
"ownerId" INTEGER NOT NULL,
"ownerId" TEXT NOT NULL,
"discordInvite" TEXT NOT NULL,
"twitter" TEXT,
@@ -33,7 +33,7 @@ CREATE TABLE "Organization" (
-- CreateTable
CREATE TABLE "Tournament" (
"id" SERIAL NOT NULL,
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"nameForUrl" TEXT NOT NULL,
"description" TEXT,
@@ -41,7 +41,7 @@ CREATE TABLE "Tournament" (
"checkInTime" TIMESTAMP(3) NOT NULL,
"bannerBackground" TEXT NOT NULL,
"bannerTextHSLArgs" TEXT NOT NULL,
"organizerId" INTEGER NOT NULL,
"organizerId" TEXT NOT NULL,
CONSTRAINT "Tournament_pkey" PRIMARY KEY ("id")
);
@@ -57,10 +57,10 @@ CREATE TABLE "Stage" (
-- CreateTable
CREATE TABLE "TournamentTeam" (
"id" SERIAL NOT NULL,
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"checkedIn" BOOLEAN NOT NULL DEFAULT false,
"tournamentId" INTEGER NOT NULL,
"tournamentId" TEXT NOT NULL,
"inviteCode" TEXT NOT NULL,
CONSTRAINT "TournamentTeam_pkey" PRIMARY KEY ("id")
@@ -68,23 +68,23 @@ CREATE TABLE "TournamentTeam" (
-- CreateTable
CREATE TABLE "TournamentTeamMember" (
"memberId" INTEGER NOT NULL,
"teamId" INTEGER NOT NULL,
"tournamentId" INTEGER NOT NULL,
"memberId" TEXT NOT NULL,
"teamId" TEXT NOT NULL,
"tournamentId" TEXT NOT NULL,
"captain" BOOLEAN NOT NULL DEFAULT false
);
-- CreateTable
CREATE TABLE "TrustRelationships" (
"trustGiverId" INTEGER NOT NULL,
"trustReceiverId" INTEGER NOT NULL,
"trustGiverId" TEXT NOT NULL,
"trustReceiverId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "_StageToTournament" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL
"B" TEXT NOT NULL
);
-- CreateIndex

View File

@@ -8,7 +8,7 @@ datasource db {
}
model User {
id Int @id @default(autoincrement())
id String @id @default(uuid())
discordId String @unique
discordName String
discordDiscriminator String
@@ -27,11 +27,11 @@ model User {
}
model Organization {
id Int @id @default(autoincrement())
id String @id @default(uuid())
name String
/// Name in lower case to show in URL
nameForUrl String @unique
ownerId Int @unique
ownerId String @unique
owner User @relation(fields: [ownerId], references: [id])
discordInvite String
twitter String?
@@ -39,7 +39,7 @@ model Organization {
}
model Tournament {
id Int @id @default(autoincrement())
id String @id @default(uuid())
name String
/// Name in lower case to show in URL
nameForUrl String
@@ -51,7 +51,7 @@ model Tournament {
/// CSS for tournament banner's color value
bannerTextHSLArgs String
mapPool Stage[]
organizerId Int
organizerId String
organizer Organization @relation(fields: [organizerId], references: [id])
teams TournamentTeam[]
@@ -75,10 +75,10 @@ model Stage {
}
model TournamentTeam {
id Int @id @default(autoincrement())
id String @id @default(uuid())
name String
checkedIn Boolean @default(false)
tournamentId Int
tournamentId String
tournament Tournament @relation(fields: [tournamentId], references: [id])
inviteCode String @default(uuid())
members TournamentTeamMember[]
@@ -87,9 +87,9 @@ model TournamentTeam {
}
model TournamentTeamMember {
memberId Int
teamId Int
tournamentId Int
memberId String
teamId String
tournamentId String
captain Boolean @default(false)
team TournamentTeam @relation(fields: [teamId], references: [id])
member User @relation(fields: [memberId], references: [id])
@@ -101,8 +101,8 @@ model TournamentTeamMember {
// to add them to a tournament team
// / LFG group without them having to click a link.
model TrustRelationships {
trustGiverId Int
trustReceiverId Int
trustGiverId String
trustReceiverId String
trustGiver User @relation("trustGiver", fields: [trustGiverId], references: [id])
trustReceiver User @relation("trustReceiver", fields: [trustReceiverId], references: [id])
createdAt DateTime @default(now())

View File

@@ -103,7 +103,7 @@ async function users() {
});
}
async function tournamentTeams(tournamentId: number, users: number[]) {
async function tournamentTeams(tournamentId: string, users: string[]) {
const randomIds = faker.helpers.shuffle(users);
for (let index = 0; index < 24; index++) {
const team = await prisma.tournamentTeam.create({
@@ -127,7 +127,7 @@ async function tournamentTeams(tournamentId: number, users: number[]) {
}
}
async function organizations(userId: number) {
async function organizations(userId: string) {
return prisma.organization.create({
data: {
name: "Sendou's Tournaments",
@@ -141,7 +141,7 @@ async function organizations(userId: number) {
const modesList = ["TW", "SZ", "TC", "RM", "CB"] as const;
async function tournaments(organizationId: number) {
async function tournaments(organizationId: string) {
return prisma.tournament.create({
data: {
bannerBackground: "linear-gradient(to bottom, #9796f0, #fbc7d4)",
@@ -157,7 +157,7 @@ async function tournaments(organizationId: number) {
}
// TODO: why this can't be done while creating?
async function tournamentAddMaps(id: number) {
async function tournamentAddMaps(id: string) {
const ids = Array.from(
new Set(
new Array(24)