https://www.prisma.io/ logo
Join Slack
Powered by
# prisma-migrate
  • p

    Pranav Sathyanarayanan

    06/15/2021, 4:14 PM
    I am currently getting:
    Copy code
    The migration `20210611143319_denormalized_current_employer` was modified after it was applied.
    While running
    prisma migrate dev --create-only --name=...
    , the CLI is saying it has to drop all data and re-add. I haven't modified this script at all, is there a way to override this?
  • c

    Casey Chow

    06/15/2021, 9:48 PM
    Hey there! Is there a blessed solution for migrating…ahem…migrations? I’m thinking about moving from TypeORM to Prisma and it seems like migrations are usually the best way to test the waters.
  • a

    Albert Gao

    06/17/2021, 12:56 AM
    I have a schema like this:
    url
    is the online database, and
    shadowDatabaseUrl
    is the local url. But still, when I run command like
    migrate reset
    , it still uses the
    url
    rather than
    shadowDatabaseUrl
    What am I missing here?
    j
    • 2
    • 1
  • a

    Albert Gao

    06/17/2021, 12:56 AM
    do I need to swap the
    .env
    file…?
    j
    • 2
    • 3
  • p

    Peter Kim

    06/17/2021, 12:12 PM
    Is there a way to set up a
    @relation
    without creating foreign key constraints in the database(mysql)? When I do
    prisma db push
    , the foreign key constraint is not created, but
    prisma migrate dev
    tries to create it. In typeorm
    Copy code
    @ManyToOne(type => Person, {
      createForeignKeyConstraints: false
    })
    I’m looking for an option similar to this.
    j
    • 2
    • 7
  • s

    sven

    06/24/2021, 1:07 PM
    Is there a way to rename a table without dropping all data?
    a
    • 2
    • 8
  • j

    John Peña

    06/24/2021, 2:22 PM
    is there a way to use prisma to create and deploy data migrations? i.e., migrations that don’t alter tables or columns, and just insert or update rows
    s
    j
    a
    • 4
    • 6
  • m

    Mikastark

    07/02/2021, 9:12 AM
    Hello everyone 🙂 I need a little bit of help for some conception issue. Let me present you a simplified version of my schema :
    Copy code
    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["referentialActions"]
    }
    
    datasource db {
      provider = "mysql"
      url      = env("DATABASE_URL")
    }
    
    model Link {
      id                  String            @id @default(uuid())
      href                String
      content             String
      androidLinkSite     Site?             @relation("androidLinkToSite")
      iOSLinkSite         Site?             @relation("iOSLinkToSite")
    }
    
    model Site {
      id                     String            @id @default(uuid())
      iOSLink                Link?             @relation("iOSLinkToSite", fields: [iOSLinkId], references: [id])
      iOSLinkId              String?
      androidLink            Link?             @relation("androidLinkToSite", fields: [androidLinkId], references: [id])
      androidLinkId          String?
    }
    I have
    sites
    that have different sorts of
    links
    . In this case an
    androidLink
    and an
    iOSLink
    (both are 1-to-1 relationship). What I want to do is when a
    site
    is deleted, it should delete also it
    androidLink
    and
    iOSLink
    . How can I archieve this ? One solution can be moving foreign keys from Site to Link and using cascade delete on Link . But it's seems ugly to me as it will polluate my Link table with many potentially unnecessary columns
  • n

    Nimish Gupta

    07/06/2021, 6:16 PM
    Hello prisma team, Hope everyone is doing great. I have a question with respect to prisma migrate. So right now current state of schema.prisma file is this
    Copy code
    enum Position {
      First
      Second
      Last
    }
    
    model Test {
      id        String     @id @default(uuid())
      name      String     @unique
      positions Position[]
    
      // common fields
      createdAt DateTime @default(now()) @map("created_at")
      updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
    
      @@map("test")
    }
    Now I am removing one value (Last) from enum 
    Position
    . So after removing I ran this command:
    prisma generate --schema=./schema.prisma && prisma migrate dev --schema=./schema.prisma
    Above command created a new migration file like this
    Copy code
    /*
      Warnings:
    
      - The values [Last] on the enum `Position` will be removed. If these variants are still used in the database, this will fail.
    
    */
    -- AlterEnum
    BEGIN;
    CREATE TYPE "Position_new" AS ENUM ('First', 'Second');
    ALTER TABLE "test" ALTER COLUMN "positions" TYPE "Position_new" USING ("positions"::text::"Position_new");
    ALTER TYPE "Position" RENAME TO "Position_old";
    ALTER TYPE "Position_new" RENAME TO "Position";
    DROP TYPE "Position_old";
    COMMIT;
    Now if I rerun 
    prisma migrate dev --schema=./schema.prisma
     , it should not do any change, because I haven't changed any thing and all the migrations should be completed with above migration file. But it is again asking for a new migration name and when I entered some name for migration it errors by this. Also it created one more migration file
    Copy code
    /*
      Warnings:
    
      - Changed the column `positions` on the `test` table from a scalar field to a list field. If there are non-null values in that column, this step will fail.
    
    */
    -- AlterTable
    ALTER TABLE "test" ALTER COLUMN "positions" SET DATA TYPE "Position"[];
    Here I couldn't understand why it is again asking for a new migration and even though we are giving it name it is throwing error. Prisma version - 2.26.0
    j
    • 2
    • 4
  • k

    Kevin Huang

    07/07/2021, 2:54 PM
    Hey folks, I'm running into an issue with failed migration. Getting the following error from my build logs
    Copy code
    10:22:13.228  	Error: P3009
    10:22:13.228  	migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    10:22:13.228  	The `20210702212552_add_unique_constraint_to_job` migration started at 2021-07-07 13:52:17.927259 UTC failed with the following logs:
    10:22:13.245  	error Command failed with exit code 1.
    And this is the migrate from the error above:
    Copy code
    /*
      Warnings:
    
      - A unique constraint covering the columns `[queueId]` on the table `Job` will be added. If there are existing duplicate values, this will fail.
      - Made the column `vendorResponded` on table `Job` required. This step will fail if there are existing NULL values in that column.
      - Made the column `status` on table `Job` required. This step will fail if there are existing NULL values in that column.
    
    */
    -- AlterTable
    ALTER TABLE "Job" ALTER COLUMN "vendorResponded" SET NOT NULL,
    ALTER COLUMN "status" SET NOT NULL;
    
    -- CreateIndex
    CREATE UNIQUE INDEX "Job.queueId_unique" ON "Job"("queueId");
    I'm assuming the issue is coming from added
    REQUIRED
    constraint to
    vendorRespond
    and
    status
    columns. I'm trying to following along this guide here to resolve the issue, I'm a bit confused on how to approach it. Where are you supposed to run this command in the guide? From your local machine or you need to ssh into the production machine to do so? Many thanks!
    Copy code
    prisma migrate resolve --rolled-back "20201127134938_added_bio_index"
    j
    • 2
    • 8
  • a

    Adam

    07/12/2021, 8:32 PM
    What is the best practice for altering migrations made prior to the fix for enums being created in a specific schema? I.E. in our first migration we created the base image to start with which had something like
    Copy code
    CREATE TYPE "public"."TestType" AS ENUM ('FOO', 'BAR', 'BAZ');
    We manually altered these files to take out the schema so our automated tests could run correctly
    Copy code
    CREATE TYPE "TestType" AS ENUM ('FOO', 'BAR', 'BAZ');
    But altering the migration manually results in a warning in prisma and probably isn't the best thing to do for our production systems I would think?
    t
    • 2
    • 2
  • i

    iamtheworstdev

    07/13/2021, 7:58 PM
    if I follow - https://www.prisma.io/docs/guides/database/advanced-database-tasks/sql-views-postgres - so that I can use prisma to query a model.. how do I make sure
    migrate
    doesn't try to create tables for those models
    t
    • 2
    • 1
  • i

    iamtheworstdev

    07/13/2021, 8:00 PM
    lol nm the solution is don't use a cheap hack to query views https://github.com/prisma/prisma/issues/678
  • c

    Carlos Gomez

    07/14/2021, 7:34 PM
    Hi, I'm creating a Circle CI config and it seems to be working, for the most part. My job steps are 1) initialize the postgres container 2)
    prisma migrate deploy
    (per the docs) 3) run tests (1 test does a
    create
    , then a
    findAll
    , and it's passing) After running
    prisma migrate deploy
    , my postgres container shows an error (in thread)
    • 1
    • 1
  • m

    Mischa

    07/15/2021, 6:30 AM
    Hi I've been posting a bit on GitHub trying to share what I'm trying to accomplish with DB migrations and adding a prisma lambda layer to functions in my CDK app. I created a WIP PR to try to put my ideas into code to create reusable constructs and utilities for using Prisma in lambda functions with CDK. Suggestions and feedback would be most appreciated: https://github.com/jetbridge/jetkit-cdk/pull/13
    💯 1
    t
    • 2
    • 2
  • j

    Jon Deibel

    07/16/2021, 2:59 PM
    Is it possible to upgrade from migrate 2.2.0 to 2.27.0 without nuking the whole DB?
    j
    • 2
    • 8
  • a

    Alexander Braunreuther

    07/19/2021, 7:05 AM
    Hi there 👋 I’m deploying a postgres db in a k8s project (PG is managed by cloud provider). The db should be in the VPC and no available from outside (so no connection from buildsystem - GH Actions). Is there a common way to apply the migrations in such a scenario? I guess it’s a normal k8s setup
    j
    • 2
    • 2
  • s

    sven

    07/27/2021, 1:18 PM
    We just had a weird experience that i dont understand: 1. We ran migrate deploy (adding a
    @unique
    ) through pgbouncer as we always do (and it usually works well) 2. The migrate failed because we had duplicate entries 3. We removed the duplicate entries and re-ran migrate deploy 4. Then we saw
    Error querying the database: db error: ERROR: relation "_prisma_migrations" already exists
    5. We deleted the failed migration from the table and re-ran migrate deploy 6. Still the same error from 4. 7. We ran migrate deploy directly against the database (no pgbouncer) and this worked! We solved it, but I thought maybe this helps someone, so there it is.
    💡 1
    d
    • 2
    • 2
  • d

    Daan Helsloot

    08/02/2021, 8:15 AM
    Hi guys, I have been trying to migrate our prisma version from 2.8 -> 2.28 so we can use the new migrate function. I have deleted the old migrations and hit the
    prisma migrate dev --name init
    command which gives me the ouput found in the attachment. Is there a way to use the new functionality without wiping the entire database? Many thanks!
    r
    • 2
    • 19
  • t

    Tanmay Naik

    08/07/2021, 11:09 AM
    I'm getting a P3003 error and the page it links to in the documentation is dead - https://www.prisma.io/docs/reference/api-reference/error-reference#p3003
    r
    • 2
    • 9
  • t

    Tanmay Naik

    08/07/2021, 11:11 AM
    Oh, nevermind, it's just an extra quote in the link, but still, it just links to the standard migrate page?
  • m

    Mischa

    08/10/2021, 9:28 AM
    My lambda layer for running my app and migrations - bummer that the dependencies for prisma clock in at 80MB 😩 (not counting @prisma/sdk or @prisma/migrate)
    r
    p
    • 3
    • 11
  • r

    Richard Dunlap

    08/12/2021, 4:01 PM
    When testing out an initial migration locally, it seems that primsa dropped my whole database. Is this normal? It's going to cause a lot of issues if I can't start using prisma without deleting all my data
    c
    r
    • 3
    • 2
  • n

    Neil Oliver

    08/19/2021, 8:55 AM
    I am hoping that someone may be able to help me. I am trying to make the move from using mongoose to prisma (mongodb), where i hav an existing dataset. I know that there are some changes that need to be made to the database. I have already found that the collection names names need to be changed (from plural to single), but are there other changes that are needed? Currently I cannot get any of my relationships to work (this could easily be an issue in another part of the code, however i wanted to check it was not a db issue). Thanks!
    j
    • 2
    • 5
  • s

    SKhan

    08/26/2021, 2:48 AM
    Hey guys, I am facing the same problem as per this thread (https://prisma.slack.com/archives/CBFFY3066/p1627916626006700?thread_ts=1627892149.003500&amp;cid=CBFFY3066) where I needed to recreate the migration history. However, on running
    prisma generate
    , in the schema.prisma file,
    @@unique
    row is updated with a name property. Now, typescript is screaming about errors in the generated file:
    node_modules/.prisma/client/index.d.ts
    . How should I proceed?
    Copy code
    git push origin dbMigrationsReset 
    node_modules/.prisma/client/index.d.ts:18304:5 - error TS1131: Property or signature expected.
    
    18304     GoalBoard.goalOwnerId_isActive_unique?: GoalBoardGoalBoard.goalOwnerId_isActive_uniqueCompoundUniqueInput
              ~~~~~~~~~
    
    node_modules/.prisma/client/index.d.ts:18304:43 - error TS1109: Expression expected.
    
    18304     GoalBoard.goalOwnerId_isActive_unique?: GoalBoardGoalBoard.goalOwnerId_isActive_uniqueCompoundUniqueInput
                                                    ~
    
    node_modules/.prisma/client/index.d.ts:18347:5 - error TS1131: Property or signature expected.
    
    18347     Invite.fromGBId_toGBId_unique?: InviteInvite.fromGBId_toGBId_uniqueCompoundUniqueInput
              ~~~~~~
    
    node_modules/.prisma/client/index.d.ts:18347:35 - error TS1109: Expression expected.
    
    18347     Invite.fromGBId_toGBId_unique?: InviteInvite.fromGBId_toGBId_uniqueCompoundUniqueInput
                                            ~
    
    node_modules/.prisma/client/index.d.ts:18348:3 - error TS1128: Declaration or statement expected.
    
    18348   }
            ~
    
    node_modules/.prisma/client/index.d.ts:18547:5 - error TS1131: Property or signature expected.
    
    18547     TaskFrequency.taskId_completedOn_unique?: TaskFrequencyTaskFrequency.taskId_completedOn_uniqueCompoundUniqueInput
              ~~~~~~~~~~~~~
    
    node_modules/.prisma/client/index.d.ts:18547:45 - error TS1109: Expression expected.
    
    18547     TaskFrequency.taskId_completedOn_unique?: TaskFrequencyTaskFrequency.taskId_completedOn_uniqueCompoundUniqueInput
                                                      ~
    
    node_modules/.prisma/client/index.d.ts:18548:3 - error TS1128: Declaration or statement expected.
    
    18548   }
            ~
    
    node_modules/.prisma/client/index.d.ts:20835:33 - error TS1005: '=' expected.
    
    20835   export type GoalBoardGoalBoard.goalOwnerId_isActive_uniqueCompoundUniqueInput = {
                                          ~
    
    node_modules/.prisma/client/index.d.ts:20835:81 - error TS1005: ';' expected.
    
    20835   export type GoalBoardGoalBoard.goalOwnerId_isActive_uniqueCompoundUniqueInput = {
                                                                                          ~
    r
    • 2
    • 3
  • a

    Anthony Campolo

    09/02/2021, 12:22 AM
    Hello Prisma team 👋 was wondering if anyone knows what’s causing this error. I’m trying to run
    yarn rw prisma migrate dev
    , (which is basically just a wrapper around
    prisma migrate dev
    ) with a Supabase database and I’m getting this error:
    Copy code
    Error: Database error
    Error querying the database: db error: ERROR: unexpected response from login query
       0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
                 at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:375
       1: migration_core::api::DevDiagnostic
                 at migration-engine/core/src/api.rs:89
    My Prisma schema:
    Copy code
    datasource DS {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider      = "prisma-client-js"
      binaryTargets = "native"
    }
    
    model User {
      id        Int      @id @default(autoincrement())
      githubId  Int
      handle    String   @unique
      email     String   @unique
      createdAt DateTime @default(now())
    }
    
    model Repository {
      id        Int      @id @default(autoincrement())
      githubId  Int
      fullName  String
      createdAt DateTime @default(now())
    }
    Redacted
    .env
    file:
    Copy code
    DATABASE_URL=<postgres://postgres:password@db.xxxx.supabase.co:6543/postgres>
    SUPABASE_URL=<https://xxxx.supabase.co>
    SUPABASE_KEY=xxx
    SUPABASE_JWT_SECRET=xxx
    • 1
    • 1
  • j

    Josef Henryson

    09/07/2021, 7:55 AM
    Hi, I am about to migrate from Prisma 1 to 2 and reading about scalarList - the docs says that it can only be migrated to Postgresql, but I am using MySQL. Is there any way to manage this with MySQL or do I have to migrate my DB to Posstgres?
    r
    • 2
    • 8
  • m

    Marvin

    09/13/2021, 12:22 PM
    Hey! Is it correct that when I want to rename a field, I need to manually update the generated SQL file like described here (https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/customizing-migrations) or is there a way to do this automatically?
    r
    • 2
    • 2
  • s

    Schuyler Ankele

    09/14/2021, 10:39 PM
    Sorry I just found this channel but probably posted this in the wrong room earlier: https://prisma.slack.com/archives/CA491RJH0/p1631656023089800
  • j

    Josef Henryson

    09/23/2021, 2:58 PM
    Hi, I’m still struggling with trying to migrate from Prisma 1.34 to Prisma 2/3. My current task is to change my scalar arrays to regular tables / prisma types so that it will work in MySQL which we use as DB. Does anyone here have any experience with this and could you then please share some tips on how you managed this? Or do you have some other idea on how to break out from the scalar array dependency?
1...56789Latest