refactor: update prisma seed to use ts-node-esm with a mts file, not ts, and add a dummy cid string in the articles array
This commit is contained in:
parent
f94813d4c2
commit
c6849e9a2d
|
@ -3,13 +3,14 @@
|
|||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
|
||||
"seed": "ts-node-esm prisma/seed.mts"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
"lint": "next lint",
|
||||
"bridge": "ts-node-esm bridge.mts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@heroicons/react": "^2.0.18",
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import {PrismaClient} from "@prisma/client";
|
||||
import {faker} from "@faker-js/faker";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const numberOfArticles = 100; // Specify the number of articles to generate
|
||||
const articles = [];
|
||||
|
||||
for (let i = 0; i < numberOfArticles; i++) {
|
||||
const title = faker.lorem.sentence();
|
||||
const slug = faker.helpers.slugify(title).toLowerCase();
|
||||
const url = faker.internet.url();
|
||||
const siteKey = faker.string.alphanumeric(10);
|
||||
|
||||
articles.push({title, slug, cid: "", url, siteKey});
|
||||
}
|
||||
|
||||
for (const article of articles) {
|
||||
await prisma.article.create({
|
||||
data: article,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`${articles.length} articles created.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
import { PrismaClient } from "@prisma/client";
|
||||
import { faker } from "@faker-js/faker";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const numberOfArticles = 100; // Specify the number of articles to generate
|
||||
const articles = [];
|
||||
|
||||
for (let i = 0; i < numberOfArticles; i++) {
|
||||
const title = faker.lorem.sentence();
|
||||
const slug = faker.helpers.slugify(title).toLowerCase();
|
||||
const url = faker.internet.url();
|
||||
const siteKey = faker.string.alphanumeric(10);
|
||||
|
||||
articles.push({ title, slug, url, siteKey });
|
||||
}
|
||||
|
||||
for (const article of articles) {
|
||||
await prisma.article.create({
|
||||
data: article,
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`${articles.length} articles created.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
Loading…
Reference in New Issue