Remove unused

This commit is contained in:
Kalle (Sendou) 2021-06-27 18:06:13 +03:00
parent 8d4ec0d711
commit eed1856a37
11 changed files with 1 additions and 647 deletions

19
package-lock.json generated
View File

@ -66,7 +66,6 @@
"cross-env": "^7.0.3",
"eslint": "^7.29.0",
"eslint-config-next": "^11.0.0",
"fishery": "^1.3.1",
"prettier": "^2.3.1",
"prisma": "^2.25.0",
"ts-jest": "^27.0.3",
@ -6648,15 +6647,6 @@
"node": ">=8"
}
},
"node_modules/fishery": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/fishery/-/fishery-1.3.1.tgz",
"integrity": "sha512-Oto2fALKmpijLbNAMHvFTrbIPPn9Ds7olDl17qFU8d9eEiro/32wF3V/6Gq0ApabyYP+VhySKqQLiCtJPMeP1A==",
"dev": true,
"dependencies": {
"lodash.mergewith": "^4.6.2"
}
},
"node_modules/flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",
@ -20215,15 +20205,6 @@
"path-exists": "^4.0.0"
}
},
"fishery": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/fishery/-/fishery-1.3.1.tgz",
"integrity": "sha512-Oto2fALKmpijLbNAMHvFTrbIPPn9Ds7olDl17qFU8d9eEiro/32wF3V/6Gq0ApabyYP+VhySKqQLiCtJPMeP1A==",
"dev": true,
"requires": {
"lodash.mergewith": "^4.6.2"
}
},
"flat-cache": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz",

View File

@ -80,7 +80,6 @@
"cross-env": "^7.0.3",
"eslint": "^7.29.0",
"eslint-config-next": "^11.0.0",
"fishery": "^1.3.1",
"prettier": "^2.3.1",
"prisma": "^2.25.0",
"ts-jest": "^27.0.3",

View File

@ -4,7 +4,7 @@ import { PrismaClient } from "@prisma/client";
let prisma: PrismaClient;
if (!global.prisma) {
// { log: ["query", "info", "warn"] }
// if you want to show logs for the DB queries use { log: ["query", "info", "warn"] } as parameter below
global.prisma = new PrismaClient();
}

View File

@ -1,27 +0,0 @@
import { Prisma } from "@prisma/client";
import { Factory } from "fishery";
import prisma from "../client";
const TWELVE_HOURS = 43200000;
export default Factory.define<Prisma.CalendarEventCreateManyInput>(
({ sequence, onCreate }) => {
onCreate((event) => {
return prisma.calendarEvent.create({ data: event });
});
const now = new Date();
return {
date: new Date(now.getTime() + sequence * TWELVE_HOURS),
description: `# Our great event ${sequence}\nCome play`,
discordInviteUrl: "https://discord.gg/sendou",
isTournament: true,
format: "OTHER",
name: `The Event #${sequence}`,
posterId: sequence,
eventUrl: "https://challonge.com",
tags: [],
};
}
);

View File

@ -1,18 +0,0 @@
import { Prisma } from "@prisma/client";
import { Factory } from "fishery";
import { v4 as uuidv4 } from "uuid";
import prisma from "../client";
export default Factory.define<Prisma.LadderRegisteredTeamCreateManyInput>(
({ sequence, onCreate }) => {
onCreate((data) => {
return prisma.ladderRegisteredTeam.create({ data });
});
return {
id: sequence,
inviteCode: uuidv4(),
ownerId: sequence,
};
}
);

View File

@ -1,21 +0,0 @@
import { PlusStatus } from "@prisma/client";
import { Factory } from "fishery";
import { randomElement } from "../../utils/arrays";
import prisma from "../client";
export default Factory.define<PlusStatus>(({ params, onCreate }) => {
onCreate((plusStatus) => {
return prisma.plusStatus.create({ data: plusStatus });
});
return {
userId: 1, // TODO: automatically build a User object, if necessary
membershipTier: null,
region: randomElement(["EU", "NA"]),
voucherId: null,
vouchTier: null,
canVouchFor: null,
canVouchAgainAfter: null,
nameForVoting: null,
};
});

View File

@ -1,18 +0,0 @@
import { Factory } from "fishery";
import { PlusSuggestion } from "@prisma/client";
import prisma from "../client";
export default Factory.define<PlusSuggestion>(({ params, onCreate }) => {
onCreate((plusSuggestion) => {
return prisma.plusSuggestion.create({ data: plusSuggestion });
});
return {
suggestedId: 1, // TODO: automatically build a User object, if necessary
suggesterId: 2, // TODO: automatically build a User object, if necessary
tier: 1,
description: "yooo so cracked",
isResuggestion: false,
createdAt: new Date(),
};
});

View File

@ -1,20 +0,0 @@
import { Factory } from "fishery";
import { PlusVotingSummary } from "@prisma/client";
import prisma from "../client";
export default Factory.define<PlusVotingSummary>(({ params, onCreate }) => {
onCreate((plusVotingSummary) => {
return prisma.plusVotingSummary.create({ data: plusVotingSummary });
});
return {
userId: 1, // TODO: automatically build a User object, if necessary
month: 1,
tier: 1,
year: 2020,
wasVouched: false,
wasSuggested: false,
countsEU: [0, 0, 0, 3],
countsNA: [0, 0, 2, 0],
};
});

View File

@ -1,21 +0,0 @@
import { Factory } from "fishery";
import { User } from "@prisma/client";
import prisma from "../client";
export default Factory.define<User>(({ sequence, onCreate }) => {
onCreate((user) => {
return prisma.user.create({ data: user });
});
return {
id: sequence,
discordId: sequence.toString().padStart(17, "0"),
discordAvatar: null,
discriminator: sequence.toString().padStart(4, "0"),
username: `User${sequence}`,
patreonTier: 0,
canPostEvents: false,
teamId: null,
ladderTeamId: null,
};
});

View File

@ -1,152 +0,0 @@
import { PlusRegion, Prisma } from "@prisma/client";
import plusStatusFactory from "../factories/plusStatus";
import plusSuggestionFactory from "../factories/plusSuggestion";
import plusVotingSummaryFactory from "../factories/plusVotingSummary";
// TODO: All this data is currently hard-coded so that Cypress tests will pass.
// In the future, we could allow the data generated by these factories be more random, and
// update the tests so that they are responsible for creating the specific data that they want to check.
export const getPlusStatusesData = (): Prisma.PlusStatusCreateManyInput[] => {
return [
{
userId: 1,
canVouchAgainAfter: new Date(Date.UTC(2020, 1, 1)),
},
{
userId: 2,
},
{
userId: 3,
},
{
userId: 4,
},
{
userId: 5,
},
{
userId: 6,
membershipTier: 2,
vouchTier: 1,
},
{
userId: 7,
membershipTier: 2,
},
{
userId: 8,
membershipTier: 2,
},
{
userId: 9,
membershipTier: 2,
},
{
userId: 10,
},
{
userId: 333,
region: PlusRegion.EU,
membershipTier: 2,
canVouchAgainAfter: new Date(Date.UTC(2030, 1, 1)),
canVouchFor: 2,
},
{
userId: 999,
region: PlusRegion.EU,
canVouchFor: 1,
membershipTier: 1,
},
].map((params) => {
return plusStatusFactory.build(params);
});
};
export const getPlusSuggestionsData =
(): Prisma.PlusSuggestionCreateManyInput[] => {
return [
plusSuggestionFactory.build({
description: "yooo so cracked",
tier: 2,
suggestedId: 10,
suggesterId: 1,
}),
];
};
export const getPlusVotingSummaryData =
(): Prisma.PlusVotingSummaryCreateManyInput[] => {
return [
{
userId: 1,
countsEU: [0, 0, 0, 3],
countsNA: [0, 0, 2, 0],
},
{
userId: 2,
countsEU: [0, 3, 0, 0],
countsNA: [2, 0, 0, 0],
},
{
userId: 3,
countsEU: [1, 1, 1, 0],
countsNA: [0, 1, 1, 0],
},
{
userId: 4,
countsEU: [0, 1, 2, 0],
countsNA: [2, 0, 0, 0],
},
{
userId: 5,
countsEU: [1, 0, 1, 1],
countsNA: [0, 2, 0, 0],
},
{
userId: 6,
wasVouched: true,
countsEU: [0, 3, 0, 0],
countsNA: [2, 0, 0, 0],
},
{
userId: 7,
wasVouched: true,
countsEU: [0, 0, 0, 3],
countsNA: [0, 0, 2, 0],
},
// +2
{
userId: 6,
tier: 2,
countsEU: [0, 0, 2, 0],
countsNA: [0, 0, 0, 2],
},
{
userId: 7,
tier: 2,
countsEU: [0, 1, 0, 1],
countsNA: [0, 1, 1, 0],
},
{
userId: 8,
tier: 2,
countsEU: [0, 2, 0, 0],
countsNA: [0, 0, 2, 0],
},
{
userId: 9,
tier: 2,
countsEU: [1, 1, 0, 0],
countsNA: [0, 2, 0, 0],
},
{
userId: 10,
tier: 2,
countsEU: [0, 0, 2, 0],
countsNA: [0, 0, 0, 2],
},
].map((params) => {
return plusVotingSummaryFactory.build(params);
});
};

View File

@ -1,349 +0,0 @@
import fs from "fs";
import path from "path";
import prisma from "./client";
import calendarEventFactory from "./factories/calendarEvent";
import ladderRegisteredTeamFactory from "./factories/ladderRegisteredTeam";
import userFactory from "./factories/user";
import {
getPlusStatusesData,
getPlusSuggestionsData,
getPlusVotingSummaryData,
} from "./mocks/plus";
async function main() {
throwIfNotLocalhost();
await dropAllData();
await seedNewData();
}
function throwIfNotLocalhost() {
fs.readFile(
path.join(process.cwd(), "prisma", ".env"),
function (err: any, data: any) {
if (!err) {
for (const line of data.toString().split("\n")) {
if (!line.startsWith("DATABASE_URL=")) {
continue;
}
if (!line.includes("localhost:")) {
console.error("trying to seed a database not in localhost");
process.exit(1);
}
}
} else {
console.error(err);
process.exit(1);
}
}
);
}
async function dropAllData() {
// TODO: Programatically clear/truncate all tables, rather than listing each model individually
// That way, we won't need to update this method each time we add a new model
await prisma.profile.deleteMany({});
await prisma.build.deleteMany({});
await prisma.salmonRunRecord.deleteMany({});
await prisma.freeAgentPost.deleteMany({});
await prisma.team.deleteMany({});
await prisma.ladderPlayerTrueSkill.deleteMany({});
await prisma.ladderMatchPlayer.deleteMany({});
await prisma.plusVotingSummary.deleteMany({});
await prisma.plusSuggestion.deleteMany({});
await prisma.plusStatus.deleteMany({});
await prisma.calendarEvent.deleteMany({});
await prisma.plusBallot.deleteMany({});
await prisma.user.deleteMany({});
}
async function seedNewData() {
await seedUsers();
await seedEvents();
await seedLadderData();
await prisma.plusStatus.createMany({ data: getPlusStatusesData() });
await prisma.plusSuggestion.createMany({ data: getPlusSuggestionsData() });
await prisma.plusVotingSummary.createMany({
data: getPlusVotingSummaryData(),
});
}
async function seedUsers() {
const randomUsers = [...Array(10)].map((_, _i) => {
return userFactory.build();
});
await prisma.user.createMany({
data: [
...randomUsers,
userFactory.build({ username: "NZAP", id: 333 }),
userFactory.build({
username: "Sendou",
patreonTier: 1,
id: 999,
discordId: "79237403620945920",
}),
],
});
}
async function seedEvents() {
const randomEvents = [...Array(10)].map((_, _i) => {
return calendarEventFactory.build();
});
await prisma.calendarEvent.createMany({
data: [
...randomEvents,
calendarEventFactory.build({
name: "Should Not Show",
posterId: 999,
date: new Date(new Date().getTime() - 143200000),
}),
calendarEventFactory.build({
name: "In The Zone Ultimate",
posterId: 999,
format: "DE",
tags: ["SZ"],
description: "Ultimate zoning",
}),
calendarEventFactory.build({
name: "Low Ink All Year",
posterId: 333,
format: "SWISS2SE",
tags: ["LOW", "MULTIPLE", "ART"],
}),
],
});
}
async function seedLadderData() {
const twentyFourHoursFromNow = new Date(
new Date().getTime() + 24 * 60 * 60 * 1000
);
twentyFourHoursFromNow.setHours(12, 0, 0);
await prisma.ladderDay.createMany({
data: [
{
id: 1,
date: new Date(twentyFourHoursFromNow.getTime() - 24 * 60 * 60 * 1000),
},
{
id: 2,
date: twentyFourHoursFromNow,
},
],
});
await prisma.ladderRegisteredTeam.createMany({
data: [...Array(2)].map((_, _i) => {
return ladderRegisteredTeamFactory.build();
}),
});
await Promise.all([
prisma.user.updateMany({
where: { id: { in: [1, 2, 3, 4] } },
data: { ladderTeamId: 1 },
}),
prisma.user.updateMany({
where: { id: { in: [5, 6, 7] } },
data: { ladderTeamId: 2 },
}),
]);
await prisma.ladderMatch.create({
data: {
id: 1,
dayId: 1,
maplist: [
{
stage: "The Reef",
mode: "SZ",
},
{
stage: "Musselforge Fitness",
mode: "CB",
},
{
stage: "Starfish Mainstage",
mode: "SZ",
},
{
stage: "Humpback Pump Track",
mode: "TC",
},
{
stage: "Inkblot Art Academy",
mode: "SZ",
},
{
stage: "Sturgeon Shipyard",
mode: "RM",
},
{
stage: "Manta Maria",
mode: "SZ",
},
{
stage: "Snapper Canal",
mode: "CB",
},
{
stage: "Blackbelly Skatepark",
mode: "SZ",
},
],
order: 1,
teamAScore: 5,
teamBScore: 0,
},
});
// await prisma.ladderMatch.createMany({
// data: [
// {
// id: 1,
// dayId: 1,
// maplist: [
// {
// stage: "The Reef",
// mode: "SZ",
// },
// {
// stage: "Musselforge Fitness",
// mode: "CB",
// },
// {
// stage: "Starfish Mainstage",
// mode: "SZ",
// },
// {
// stage: "Humpback Pump Track",
// mode: "TC",
// },
// {
// stage: "Inkblot Art Academy",
// mode: "SZ",
// },
// {
// stage: "Sturgeon Shipyard",
// mode: "RM",
// },
// {
// stage: "Manta Maria",
// mode: "SZ",
// },
// {
// stage: "Snapper Canal",
// mode: "CB",
// },
// {
// stage: "Blackbelly Skatepark",
// mode: "SZ",
// },
// ],
// order: 1,
// teamAScore: 5,
// teamBScore: 0,
// },
// {
// id: 2,
// dayId: 1,
// maplist: [
// {
// stage: "MakoMart",
// mode: "SZ",
// },
// {
// stage: "Shellendorf Institute",
// mode: "TC",
// },
// {
// stage: "Goby Arena",
// mode: "SZ",
// },
// {
// stage: "Piranha Pit",
// mode: "CB",
// },
// {
// stage: "Camp Triggerfish",
// mode: "SZ",
// },
// {
// stage: "Wahoo World",
// mode: "RM",
// },
// {
// stage: "New Albacore Hotel",
// mode: "SZ",
// },
// {
// stage: "Ancho-V Games",
// mode: "TC",
// },
// {
// stage: "Skipper Pavilion",
// mode: "SZ",
// },
// ],
// order: 2,
// },
// ],
// });
await prisma.ladderMatchPlayer.createMany({
data: [
{
matchId: 1,
team: "ALPHA",
userId: 1,
},
{
matchId: 1,
team: "ALPHA",
userId: 2,
},
{
matchId: 1,
team: "ALPHA",
userId: 3,
},
{
matchId: 1,
team: "ALPHA",
userId: 4,
},
{
matchId: 1,
team: "BRAVO",
userId: 5,
},
{
matchId: 1,
team: "BRAVO",
userId: 6,
},
{
matchId: 1,
team: "BRAVO",
userId: 7,
},
{
matchId: 1,
team: "BRAVO",
userId: 8,
},
],
});
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});