Skip to content

Conversation

@onozaty
Copy link
Owner

@onozaty onozaty commented Nov 9, 2025

Summary

Fixes the bug where migrations were created in the wrong location when using multi-file Prisma schema configuration (issue #20).

Problem

When using --schema pointing to a folder (multi-file schema), the generator was creating migrations in ./schema/migrations/ instead of the correct location at the same level as the schema folder.

Root cause: The code was using path.dirname(schemaPath) which pointed to the schema folder itself, not its parent directory.

Solution

  • Use config.outputDir (already correctly resolved by Prisma) instead of path.dirname(schemaPath)
  • Remove unused schemaPath variable from generate function
  • Rename baseDirPath parameter to migrationsDir for better clarity

Changes

  • generator.ts: Updated to use config.outputDir for migration base path
  • generator.test.ts:
    • Added multi-file-schema test case
    • Extended executeGenerate helper to handle multi-file schema
    • Extended getMigrationsDir helper to handle multi-file schema
  • Test fixtures: Added multi-file-schema fixture with 3 schema files

Test Results

✅ All 55 tests passing
✅ New test case for multi-file schema configuration
✅ Backward compatible - single-file schema behavior unchanged

Test plan

  • Run all existing tests
  • Add new test for multi-file schema
  • Verify migrations are created in correct location
  • Verify backward compatibility with single-file schema

Fixes #20

When using multi-file Prisma schema configuration (--schema pointing to a folder),
the migrations were being created in the wrong location because the code was using
path.dirname(schemaPath) which pointed to the schema folder itself.

Changes:
- Use config.outputDir (already correctly resolved by Prisma) instead of path.dirname(schemaPath)
- Remove unused schemaPath variable from generate function
- Rename baseDirPath parameter to migrationsDir for clarity
- Add test fixture for multi-file schema configuration
- Update test helpers (executeGenerate, getMigrationsDir) to support multi-file schema

Fixes #20
@codecov
Copy link

codecov bot commented Nov 9, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.41%. Comparing base (a9e8bc7) to head (4928584).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/generator.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #21   +/-   ##
=======================================
  Coverage   81.41%   81.41%           
=======================================
  Files           7        7           
  Lines         382      382           
  Branches       90       90           
=======================================
  Hits          311      311           
  Misses         71       71           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@onozaty onozaty requested review from Copilot and removed request for Copilot November 9, 2025 04:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for multi-file Prisma schemas by changing the migration directory resolution from using schemaPath to using the generator's outputDir configuration. This allows the generator to correctly place migrations relative to the schema location, whether it's a single file or a directory containing multiple schema files.

  • Migration output directory now uses config.outputDir instead of path.dirname(schemaPath)
  • Parameter renamed from baseDirPath to migrationsDir for better clarity
  • Migration path construction simplified to directly use the migrations directory

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/generator.ts Updated migration directory resolution to use config.outputDir and simplified path construction
src/generator.test.ts Added test case for multi-file-schema support with appropriate directory handling
src/snapshots/generator.test.ts.snap Added expected snapshots for multi-file-schema test outputs
src/fixtures/multi-file-schema/schema/schema.prisma Created main schema configuration file for multi-file-schema test fixture
src/fixtures/multi-file-schema/schema/user.prisma Created User model definition for multi-file-schema test fixture
src/fixtures/multi-file-schema/schema/post.prisma Created Post model definition for multi-file-schema test fixture

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@onozaty onozaty merged commit 39440a2 into main Nov 9, 2025
14 of 15 checks passed
@onozaty onozaty deleted the 20-bug-multi-file-prisma-schema-configuration-fails-to-correctly-locate-migrations-folder branch November 9, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Multi-file Prisma schema configuration fails to correctly locate migrations folder

2 participants