Skip to content

Commit

Permalink
Try hacky seed script run
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsilvestre committed Dec 8, 2023
1 parent f614fe0 commit 248e35d
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 145 deletions.
9 changes: 8 additions & 1 deletion app/routes/dict.$figureId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ interface LoaderData {
searchedFigure: DictionaryPageSearchedFigure;
}

export const meta: MetaFunction = () => [{ title: "Figure entry" }];
export const meta: MetaFunction<typeof loader> = (a) => [
{
title:
[...(a.params.figureId || "")].length === 1
? `${a.params.figureId} | Kanjisense`
: "Kanjisense",
},
];

export const links: LinksFunction = () => [
{
Expand Down
62 changes: 53 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.7",
"prisma": "^5.5.2",
"prisma": "^5.7.0",
"start-server-and-test": "^2.0.1",
"tailwindcss": "^3.3.3",
"ts-node": "^10.9.1",
Expand Down
135 changes: 1 addition & 134 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,140 +1,7 @@
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";

import { seedKanjiDbComposition } from "./external/seedKanjiDbComposition";
import { seedKanjiDbSbgyNotes } from "./external/seedKanjiDbSbgyNotes";
import { seedKanjiDbVariants } from "./external/seedKanjiDbVariants";
import { seedKanjidic } from "./external/seedKanjidic";
import { seedSbgy } from "./external/seedSbgy";
import { seedScriptinAozoraFrequencies } from "./external/seedScriptinAozoraFrequencies";
import { seedUnihan12 } from "./external/seedUnihan12";
import { seedUnihan14 } from "./external/seedUnihan14";
import { seedUnihan15 } from "./external/seedUnihan15";
import { executeAndLogTime } from "./kanjisense/executeAndLogTime";
import { seedFigureSearchProperties } from "./kanjisense/seedFigureSearchProperties";
import { seedGlyphImages } from "./kanjisense/seedGlyphImages";
import { seedKanjiDbCharacterDerivations } from "./kanjisense/seedKanjiDbCharacterDerivations";
import { seedKanjisenseActiveSoundMarks } from "./kanjisense/seedKanjisenseActiveSoundMarks";
import { seedKanjisenseActiveSoundMarkValues } from "./kanjisense/seedKanjisenseActiveSoundMarkValues";
import { seedFigureImages } from "./kanjisense/seedKanjisenseFigureImages";
import { seedKanjisenseFigureReadings } from "./kanjisense/seedKanjisenseFigureReadings";
import { seedKanjisenseFigureRelation } from "./kanjisense/seedKanjisenseFigureRelation";
import { seedKanjisenseFigures } from "./kanjisense/seedKanjisenseFigures";
import { seedKanjisenseFigureBadgeProps } from "./kanjisense/seedKanjisenseFiguresBadgeProps";
import { seedKanjisenseVariantGroups } from "./kanjisense/seedKanjisenseVariantGroups";
import { seedShuowenImages } from "./kanjisense/seedShuowenImages";
import { seedJMDict } from "./seedJMDict";

import { seed } from "./seedScript";
const prisma = new PrismaClient();

async function seed() {
const startTime = Date.now();
try {
await executeAndLogTime("seeding kanjidic", () => seedKanjidic(prisma));
await executeAndLogTime("seeding unihan15", () => seedUnihan15(prisma));
await executeAndLogTime("seeding unihan14", () => seedUnihan14(prisma));
await executeAndLogTime("seeding unihan12", () => seedUnihan12(prisma));
await executeAndLogTime("seeding kanjiDB composition data", () =>
seedKanjiDbComposition(prisma),
);
await executeAndLogTime("seeding kanjiDB variants", () =>
seedKanjiDbVariants(prisma),
);
await executeAndLogTime("seeding sbgynotes", () =>
seedKanjiDbSbgyNotes(prisma),
);
await executeAndLogTime("seeding sbgy", () => seedSbgy(prisma));
await executeAndLogTime("seeding aozora frequencies", () =>
seedScriptinAozoraFrequencies(prisma),
);
await executeAndLogTime("seeding kanjisense variant groups", () =>
seedKanjisenseVariantGroups(prisma, false),
);
await executeAndLogTime("seeding kanjisense figure relations", () =>
seedKanjisenseFigureRelation(prisma, false),
);
await executeAndLogTime("seeding kanjidb character derivations", () =>
seedKanjiDbCharacterDerivations(prisma, false),
);
await executeAndLogTime("seeding kanjisense figures", () =>
seedKanjisenseFigures(prisma, false),
);
await executeAndLogTime("seeding kanjisense figure badge props", () =>
seedKanjisenseFigureBadgeProps(prisma, false),
);
await executeAndLogTime("seeding kanjisense active sound marks", () =>
seedKanjisenseActiveSoundMarks(prisma, false),
);
await executeAndLogTime("seeding JMDict", () => seedJMDict(prisma));

await executeAndLogTime("seeding kanjisense figure readings", () =>
seedKanjisenseFigureReadings(prisma, false),
);

await executeAndLogTime("seeding kanjisense active sound mark values", () =>
seedKanjisenseActiveSoundMarkValues(prisma, false),
);

await executeAndLogTime("seed figure images", () =>
seedFigureImages(prisma, false),
);

await executeAndLogTime("seeding shuowen images", () =>
seedShuowenImages(prisma, false),
);
await executeAndLogTime("seeding glyph images", () =>
seedGlyphImages(prisma, false),
);

await executeAndLogTime("seeding kanjisense figure search properties", () =>
seedFigureSearchProperties(prisma, 1000, false),
);
} catch (error) {
console.log(`❌ ${(Date.now() - startTime) / 1000}s.`);
throw error;
}
const email = "[email protected]";

// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
// no worries if it doesn't exist yet
});

const hashedPassword = await bcrypt.hash("racheliscool", 10);

const user = await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword,
},
},
},
});

await prisma.note.create({
data: {
title: "My first note",
body: "Hello, world!",
userId: user.id,
},
});

await prisma.note.create({
data: {
title: "My second note",
body: "Hello, world!",
userId: user.id,
},
});

const endTime = Date.now();

console.log(`Database has been seeded. 🌱`);
console.log(`Finished in ${(endTime - startTime) / 1000}s.`);
}

seed()
.catch((e) => {
console.error(e);
Expand Down
134 changes: 134 additions & 0 deletions prisma/seedScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";

import { seedKanjiDbComposition } from "./external/seedKanjiDbComposition";
import { seedKanjiDbSbgyNotes } from "./external/seedKanjiDbSbgyNotes";
import { seedKanjiDbVariants } from "./external/seedKanjiDbVariants";
import { seedKanjidic } from "./external/seedKanjidic";
import { seedSbgy } from "./external/seedSbgy";
import { seedScriptinAozoraFrequencies } from "./external/seedScriptinAozoraFrequencies";
import { seedUnihan12 } from "./external/seedUnihan12";
import { seedUnihan14 } from "./external/seedUnihan14";
import { seedUnihan15 } from "./external/seedUnihan15";
import { executeAndLogTime } from "./kanjisense/executeAndLogTime";
import { seedFigureSearchProperties } from "./kanjisense/seedFigureSearchProperties";
import { seedGlyphImages } from "./kanjisense/seedGlyphImages";
import { seedKanjiDbCharacterDerivations } from "./kanjisense/seedKanjiDbCharacterDerivations";
import { seedKanjisenseActiveSoundMarks } from "./kanjisense/seedKanjisenseActiveSoundMarks";
import { seedKanjisenseActiveSoundMarkValues } from "./kanjisense/seedKanjisenseActiveSoundMarkValues";
import { seedFigureImages } from "./kanjisense/seedKanjisenseFigureImages";
import { seedKanjisenseFigureReadings } from "./kanjisense/seedKanjisenseFigureReadings";
import { seedKanjisenseFigureRelation } from "./kanjisense/seedKanjisenseFigureRelation";
import { seedKanjisenseFigures } from "./kanjisense/seedKanjisenseFigures";
import { seedKanjisenseFigureBadgeProps } from "./kanjisense/seedKanjisenseFiguresBadgeProps";
import { seedKanjisenseVariantGroups } from "./kanjisense/seedKanjisenseVariantGroups";
import { seedShuowenImages } from "./kanjisense/seedShuowenImages";
import { seedJMDict } from "./seedJMDict";

export async function seed(prisma: PrismaClient) {
const startTime = Date.now();
try {
await executeAndLogTime("seeding kanjidic", () => seedKanjidic(prisma));
await executeAndLogTime("seeding unihan15", () => seedUnihan15(prisma));
await executeAndLogTime("seeding unihan14", () => seedUnihan14(prisma));
await executeAndLogTime("seeding unihan12", () => seedUnihan12(prisma));
await executeAndLogTime("seeding kanjiDB composition data", () =>
seedKanjiDbComposition(prisma),
);
await executeAndLogTime("seeding kanjiDB variants", () =>
seedKanjiDbVariants(prisma),
);
await executeAndLogTime("seeding sbgynotes", () =>
seedKanjiDbSbgyNotes(prisma),
);
await executeAndLogTime("seeding sbgy", () => seedSbgy(prisma));
await executeAndLogTime("seeding aozora frequencies", () =>
seedScriptinAozoraFrequencies(prisma),
);
await executeAndLogTime("seeding kanjisense variant groups", () =>
seedKanjisenseVariantGroups(prisma, false),
);
await executeAndLogTime("seeding kanjisense figure relations", () =>
seedKanjisenseFigureRelation(prisma, false),
);
await executeAndLogTime("seeding kanjidb character derivations", () =>
seedKanjiDbCharacterDerivations(prisma, false),
);
await executeAndLogTime("seeding kanjisense figures", () =>
seedKanjisenseFigures(prisma, false),
);
await executeAndLogTime("seeding kanjisense figure badge props", () =>
seedKanjisenseFigureBadgeProps(prisma, false),
);
await executeAndLogTime("seeding kanjisense active sound marks", () =>
seedKanjisenseActiveSoundMarks(prisma, false),
);
await executeAndLogTime("seeding JMDict", () => seedJMDict(prisma));

await executeAndLogTime("seeding kanjisense figure readings", () =>
seedKanjisenseFigureReadings(prisma, false),
);

await executeAndLogTime("seeding kanjisense active sound mark values", () =>
seedKanjisenseActiveSoundMarkValues(prisma, false),
);

await executeAndLogTime("seed figure images", () =>
seedFigureImages(prisma, false),
);

await executeAndLogTime("seeding shuowen images", () =>
seedShuowenImages(prisma, false),
);
await executeAndLogTime("seeding glyph images", () =>
seedGlyphImages(prisma, false),
);

await executeAndLogTime("seeding kanjisense figure search properties", () =>
seedFigureSearchProperties(prisma, 1000, true),
);
} catch (error) {
console.log(`❌ ${(Date.now() - startTime) / 1000}s.`);
throw error;
}
const email = "[email protected]";

// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
// no worries if it doesn't exist yet
});

const hashedPassword = await bcrypt.hash("racheliscool", 10);

const user = await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword,
},
},
},
});

await prisma.note.create({
data: {
title: "My first note",
body: "Hello, world!",
userId: user.id,
},
});

await prisma.note.create({
data: {
title: "My second note",
body: "Hello, world!",
userId: user.id,
},
});

const endTime = Date.now();

console.log(`Database has been seeded. 🌱`);
console.log(`Finished in ${(endTime - startTime) / 1000}s.`);
}

0 comments on commit 248e35d

Please sign in to comment.