From bfd8c08987be4aa38bfce5c52b4473e6c6438878 Mon Sep 17 00:00:00 2001 From: Richards0n Date: Mon, 18 Nov 2024 20:01:10 -0300 Subject: [PATCH 1/2] Add Windows support for database deployment and improve error handling in runWithProvider.js --- package.json | 3 ++- runWithProvider.js | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f7e77194e..0ca3e5a72 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "lint": "eslint --fix --ext .ts src", "db:generate": "node runWithProvider.js \"npx prisma generate --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", + "db:deploy:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate deploy --schema prisma\\DATABASE_PROVIDER-schema.prisma\"", "db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"" }, @@ -115,4 +116,4 @@ "tsconfig-paths": "^4.2.0", "typescript": "^5.5.4" } -} +} \ No newline at end of file diff --git a/runWithProvider.js b/runWithProvider.js index a82757634..154538be9 100644 --- a/runWithProvider.js +++ b/runWithProvider.js @@ -1,19 +1,31 @@ const dotenv = require('dotenv'); const { execSync } = require('child_process'); +const { existsSync } = require('fs'); + dotenv.config(); const { DATABASE_PROVIDER } = process.env; -const databaseProviderDefault = DATABASE_PROVIDER ?? "postgresql" +const databaseProviderDefault = DATABASE_PROVIDER ?? 'postgresql'; if (!DATABASE_PROVIDER) { - console.error(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`); - // process.exit(1); + console.warn(`DATABASE_PROVIDER is not set in the .env file, using default: ${databaseProviderDefault}`); } -const command = process.argv +let command = process.argv .slice(2) .join(' ') - .replace(/\DATABASE_PROVIDER/g, databaseProviderDefault); + .replace(/DATABASE_PROVIDER/g, databaseProviderDefault); + +if (command.includes('rmdir') && existsSync('prisma\\migrations')) { + try { + execSync('rmdir /S /Q prisma\\migrations', { stdio: 'inherit' }); + } catch (error) { + console.error(`Error removing directory: prisma\\migrations`); + process.exit(1); + } +} else if (command.includes('rmdir')) { + console.warn(`Directory 'prisma\\migrations' does not exist, skipping removal.`); +} try { execSync(command, { stdio: 'inherit' }); From 3582cd38fb2ca0f464625a6c57fdbb13d9f237d5 Mon Sep 17 00:00:00 2001 From: Richards0n Date: Mon, 18 Nov 2024 20:07:08 -0300 Subject: [PATCH 2/2] Add Windows support for database migration commands in package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ca3e5a72..c57c2e9ee 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "db:deploy": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate deploy --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", "db:deploy:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate deploy --schema prisma\\DATABASE_PROVIDER-schema.prisma\"", "db:studio": "node runWithProvider.js \"npx prisma studio --schema ./prisma/DATABASE_PROVIDER-schema.prisma\"", - "db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"" + "db:migrate:dev": "node runWithProvider.js \"rm -rf ./prisma/migrations && cp -r ./prisma/DATABASE_PROVIDER-migrations ./prisma/migrations && npx prisma migrate dev --schema ./prisma/DATABASE_PROVIDER-schema.prisma && cp -r ./prisma/migrations/* ./prisma/DATABASE_PROVIDER-migrations\"", + "db:migrate:dev:win": "node runWithProvider.js \"xcopy /E /I prisma\\DATABASE_PROVIDER-migrations prisma\\migrations && npx prisma migrate dev --schema prisma\\DATABASE_PROVIDER-schema.prisma\"" }, "repository": { "type": "git",