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
93
package.json
93
package.json
|
@ -1,48 +1,49 @@
|
||||||
{
|
{
|
||||||
"name": "web3.news",
|
"name": "web3.news",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
|
"seed": "ts-node-esm prisma/seed.mts"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint",
|
||||||
},
|
"bridge": "ts-node-esm bridge.mts"
|
||||||
"dependencies": {
|
},
|
||||||
"@heroicons/react": "^2.0.18",
|
"dependencies": {
|
||||||
"@prisma/client": "^5.6.0",
|
"@heroicons/react": "^2.0.18",
|
||||||
"@radix-ui/react-dialog": "^1.0.5",
|
"@prisma/client": "^5.6.0",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-dialog": "^1.0.5",
|
||||||
"@radix-ui/react-popover": "^1.0.7",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/react-scroll-area": "^1.0.5",
|
"@radix-ui/react-popover": "^1.0.7",
|
||||||
"@radix-ui/react-select": "^2.0.0",
|
"@radix-ui/react-scroll-area": "^1.0.5",
|
||||||
"@radix-ui/react-slot": "^1.0.2",
|
"@radix-ui/react-select": "^2.0.0",
|
||||||
"class-variance-authority": "^0.7.0",
|
"@radix-ui/react-slot": "^1.0.2",
|
||||||
"clsx": "^2.0.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"cmdk": "^0.2.0",
|
"clsx": "^2.0.0",
|
||||||
"date-fns": "^2.30.0",
|
"cmdk": "^0.2.0",
|
||||||
"next": "14.0.2",
|
"date-fns": "^2.30.0",
|
||||||
"react": "^18",
|
"next": "14.0.2",
|
||||||
"react-dom": "^18",
|
"react": "^18",
|
||||||
"swr": "^2.2.4",
|
"react-dom": "^18",
|
||||||
"tailwind-merge": "^2.0.0"
|
"swr": "^2.2.4",
|
||||||
},
|
"tailwind-merge": "^2.0.0"
|
||||||
"devDependencies": {
|
},
|
||||||
"@faker-js/faker": "^8.3.1",
|
"devDependencies": {
|
||||||
"@types/node": "^20",
|
"@faker-js/faker": "^8.3.1",
|
||||||
"@types/react": "^18",
|
"@types/node": "^20",
|
||||||
"@types/react-dom": "^18",
|
"@types/react": "^18",
|
||||||
"autoprefixer": "^10.0.1",
|
"@types/react-dom": "^18",
|
||||||
"eslint": "^8",
|
"autoprefixer": "^10.0.1",
|
||||||
"eslint-config-next": "14.0.2",
|
"eslint": "^8",
|
||||||
"postcss": "^8",
|
"eslint-config-next": "14.0.2",
|
||||||
"prisma": "^5.6.0",
|
"postcss": "^8",
|
||||||
"tailwindcss": "^3.3.0",
|
"prisma": "^5.6.0",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"tailwindcss": "^3.3.0",
|
||||||
"ts-node": "^10.9.1",
|
"tailwindcss-animate": "^1.0.7",
|
||||||
"typescript": "^5"
|
"ts-node": "^10.9.1",
|
||||||
}
|
"typescript": "^5"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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