Skip to content

--migrations to specify output directory for migrations #4720

Closed

Description

@janpio

With --schema we can now specify the file path of where the Prisma Schema is located, instead of the default ./prisma/schema.prisma. This has the unfortunate side effect, that migrations are also output next to that file - which might not be what you want.

We want to have a --migrations parameter that takes the path to a folder where all the migration related content is output. The default path for that parameter, if it is not supplied, thus is ./prisma/migrations.

Activity

  1. maoosi commented on Sep 24, 2020

    @maoosi

    Super keen to see this feature come to life. I use Prisma Migrate across multiple stages, so the ability to specify a different migration folder for each Stage would be quite helpful.

  2. zakthedev commented on Sep 24, 2020

    @zakthedev

    it would be better if the migrations output could be set via package.json as follows:

    "prisma": {
    "schema": "src/schema.prisma",
    "migrateOutput" : "src/migrations/"
    }

  3. maoosi commented on Sep 25, 2020

    @maoosi

    I have to somewhat disagree @rightroad, as solely relying on package.json to specify the migration output would exclude a certain number of use cases, like the one I just described around managing multiple stages from the same project. Adding an option to the CLI would allow to easily switch configs at runtime.

    That being said, it would make sense to have both options available and align with what's already in place for the Prisma schema file location: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema#prisma-schema-file-location

  4. zakthedev commented on Sep 27, 2020

    @zakthedev

    Yeah thank you for your reply @maoosi, having both options would be great! I think .env file also needs that change (or use .env on src folder) but that shouldn't be a big deal.

  5. transferred this issue fromprisma/migrateon Dec 18, 2020
  6. added
    kind/feature
    tech/typescript
    on Dec 18, 2020
  7. benhickson commented on Apr 27, 2021

    @benhickson

    Any updates on this? commenting to subscribe :)

  8. Jolg42 commented on May 5, 2021

    @Jolg42
    Contributor

    Hi there! @benhickson & others

    I'm curious about "why" this feature is needed for you, so we can prioritize better.

    Could you give example(s) where customizing the migrations folder (default is in ./prisma/migrations) is needed / better maybe?

  9. benhickson commented on May 5, 2021

    @benhickson

    Hi @Jolg42 !

    In our situation, we have a package in our monorepo for prisma. We have two databases, and each need their own prisma schema. Ideally we'd be able to commit migrations for both of them. As of now, we have to manually rename the migrations folder after running the migration, then commit that renamed folder, renaming it back to "migrations" when we want to run additional migrations. This would be unwieldy to do if we ran the migrations sequentially, but ideally we'd want to be able to run them concurrently, which wouldn't really work.

    The prisma migrate command has a --schema flag that we're already using to point to our different schemas, ideally there'd be a corresponding flag to set the migrations folder.

    As an alternative to the CLI flag, a block in the schema file would work, similar to how the generator client { } block has a output option. At least that would work for us, as our schemas and migrations are 1-to-1. Others may have setups that aren't 1-to-1.

    Open to any and all feedback on how we could do things differently!

  10. Jolg42 commented on May 5, 2021

    @Jolg42
    Contributor

    @benhickson Thank you for the detailed explanation!

    I guess a workaround could be something like this, one folder per schema:

    • ./src/db1/schema.prisma
    • ./src/db2/schema.prisma

    And then calling prisma commands with --schema="./src/db1/schema.prisma"

    Migrate will then create a migrations directory next to each schema like

    • ./src/db1/migrations/...
    • ./src/db2/migrations/...

    Is that a good enough workaround or customizing the name of the migrations directory would be better here?

  11. 9 remaining items

  12. self-assigned this
    on Nov 9, 2022
  13. carlosLMZarego commented on Apr 18, 2023

    @carlosLMZarego

    Hi there! @benhickson & others

    I'm curious about "why" this feature is needed for you, so we can prioritize better.

    Could you give example(s) where customizing the migrations folder (default is in ./prisma/migrations) is needed / better maybe?

    A good example is when you run the migration in AWS lambda and you want to use the /temp folder for instance

  14. w1am commented on May 31, 2023

    @w1am

    Hi there! @benhickson & others

    I'm curious about "why" this feature is needed for you, so we can prioritize better.

    Could you give example(s) where customizing the migrations folder (default is in ./prisma/migrations) is needed / better maybe?

    Sometimes, I write different migration files depending on my current environment. For example, I would like to populate my local database with mock data, which I wouldn't want to do in other environments. For now, I have written a script to duplicate the schema file into different folders named after my environment and specify the --schema path in the CLI.

  15. sacru2red commented on Jun 1, 2023

    @sacru2red

    I'm not sure if this is a suitable example...
    MySQL does not support multiSchema. Therefore, users create multiple schema.prisma files and also store the output in multiple directories (#16943, #2443). As a result, there is a need to manage migration files in multiple parts (since each database is separate in MySQL).

  16. pandeymangg commented on Dec 9, 2024

    @pandeymangg

    any progress on this?

  17. added
    topic: useful
    on Dec 13, 2024
  18. StiliyanKushev commented on Feb 9, 2025

    @StiliyanKushev

    +1 Bump

    Would love to see this feature come to life.

  19. batchor commented on Feb 25, 2025

    @batchor

    @jkomyno Really hope this feature can land soon!

  20. vitran96 commented on Mar 6, 2025

    @vitran96

    I am also look forward for this feature as we have a case to support both MySql and PostgreSql with same schema. Because depending on the client, we will have to switch DB.

  21. samislam commented on May 18, 2025

    @samislam

    It's been 5 years.

  22. Frost-on-Web commented on Jun 23, 2025

    @Frost-on-Web

    Actually I can't understand why this is not a basic feature.

    I agree it is mostly for convenience and personal folder organization but what is not ?

    My "wanted" Prisma folder :

    /prisma
       /schema
          /base.schema
          /user.schema
          /booking.schema
       /migrations
          /000000000000_squashed_migrations
          /202506232201_just_another_migration
       /seeds
          /main.ts
          /users.ts
    

    My "wanted" package.json :

    "prisma": {
        "schema": "prisma/schema",
        "migrations": "prisma/migrations",
        "seed": "tsx prisma/seeds/main.ts"
    },

    Easy, clear, but I can't do it like this and I am a little disappointed.
    And if there is one thing I don't like I do not like it is to be disappointed.

    (Just joking, five points for Gryffondor if you have the reference)
    Have a nice day !

  23. FGoessler commented on Jul 16, 2025

    @FGoessler
    Contributor

    Am happy announce that with Prisma 6.12.0 you can now specify your migrations folder location via prisma.config.ts. See the documentation here.

    We do not plan to add a CLI argument for this.

    Am closing this issue now as the underlying problem should be solved with this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featuretech/typescripttopic: migratetopic: useful

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions