feat: add script to create dummy seed data

This commit is contained in:
Derrick Hammer 2023-11-29 18:20:26 -05:00
parent 5c17f888d7
commit b3188b5303
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 4864 additions and 4641 deletions

9402
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,33 +1,39 @@
{ {
"name": "web3.news", "name": "web3.news",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "prisma": {
"dev": "next dev", "seed": "ts-node-esm prisma/seed.ts"
"build": "next build", },
"start": "next start", "scripts": {
"lint": "next lint" "dev": "next dev",
}, "build": "next build",
"dependencies": { "start": "next start",
"@heroicons/react": "^2.0.18", "lint": "next lint"
"@prisma/client": "^5.6.0", },
"@radix-ui/react-scroll-area": "^1.0.5", "dependencies": {
"date-fns": "^2.30.0", "@heroicons/react": "^2.0.18",
"next": "14.0.2", "@prisma/client": "^5.6.0",
"react": "^18", "@radix-ui/react-scroll-area": "^1.0.5",
"react-dom": "^18", "date-fns": "^2.30.0",
"swr": "^2.2.4" "next": "14.0.2",
}, "react": "^18",
"devDependencies": { "react-dom": "^18",
"@types/node": "^20", "swr": "^2.2.4"
"@types/react": "^18", },
"@types/react-dom": "^18", "devDependencies": {
"autoprefixer": "^10.0.1", "@faker-js/faker": "^8.3.1",
"eslint": "^8", "@types/node": "^20",
"eslint-config-next": "14.0.2", "@types/react": "^18",
"postcss": "^8", "@types/react-dom": "^18",
"tailwindcss": "^3.3.0", "autoprefixer": "^10.0.1",
"tailwindcss-animate": "^1.0.7", "eslint": "^8",
"typescript": "^5" "eslint-config-next": "14.0.2",
} "postcss": "^8",
"prisma": "^5.6.0",
"tailwindcss": "^3.3.0",
"tailwindcss-animate": "^1.0.7",
"ts-node": "^10.9.1",
"typescript": "^5"
}
} }

35
prisma/seed.ts Normal file
View File

@ -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, 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();
});