diff --git a/package.json b/package.json index f7e77194e..c57c2e9ee 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "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\"" + "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", @@ -115,4 +117,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' });