Add data migration to npm scripts

This commit is contained in:
Jorge Vargas 2025-05-10 00:36:07 -06:00
parent 5c4f46a41e
commit a5fde1b6c8
2 changed files with 6 additions and 3 deletions

View file

@ -3,10 +3,10 @@
"type": "module", "type": "module",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"start": "npm run dev", "dev": "astro dev",
"dev": "prisma generate --sql && astro dev", "build": "npm run prisma:migrate && npm run paraglide:compile && astro build",
"build": "prisma generate --sql && npm run paraglide:compile && astro build",
"preview": "astro preview", "preview": "astro preview",
"prisma:build": "prisma migrate deploy && prisma generate --sql && tsx ./prisma/migrate.ts",
"paraglide:compile": "paraglide-js compile --project ./project.inlang --outdir ./src\\paraglide" "paraglide:compile": "paraglide-js compile --project ./project.inlang --outdir ./src\\paraglide"
}, },
"dependencies": { "dependencies": {
@ -36,6 +36,7 @@
"slugify": "^1.6.6", "slugify": "^1.6.6",
"superstruct": "^2.0.2", "superstruct": "^2.0.2",
"tailwindcss": "^4.0.7", "tailwindcss": "^4.0.7",
"tsx": "^4.19.4",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"use-immer": "^0.11.0" "use-immer": "^0.11.0"
}, },

View file

@ -20,6 +20,8 @@ const migrations: Migration[] = migrationFiles
.map((id) => ({ id, migrationFn: require(path.join(dataMigrationsPath, id)).default })) .map((id) => ({ id, migrationFn: require(path.join(dataMigrationsPath, id)).default }))
.filter((migration) => migration.migrationFn !== undefined) .filter((migration) => migration.migrationFn !== undefined)
if (migrations.length === 0) console.log('No data migrations to run.')
for (const { id, migrationFn } of migrations) { for (const { id, migrationFn } of migrations) {
const startDate = new Date() const startDate = new Date()
const migration = await prismaClient.migration.findFirst({ where: { id } }) const migration = await prismaClient.migration.findFirst({ where: { id } })