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

    maxweld

    09/26/2021, 8:46 AM
    Hi. I am getting the following message during execution of a DB Push:
    ...\test-proj01> npx prisma db push
    ...
    ...
    The database is already in sync with the Prisma Schema.
    Running Generate ....
    Generated Prisma Client (3.1.1) to .\node_modules\@prisma\client in 94ms
    Error: EPERM: operation not permitted, unlink 'C:\Users\david\AppData\Roaming\npm-cache\_npx\40924\node_modules\prisma\node_modules\@prisma\engines\query_engine-windows.dll.node'
    at Object.unlinkSync (fs.js:1251:3)
    at fixWinEPERMSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:219:13)
    at rimrafSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:319:28)
    at C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:350:5
    at Array.forEach (<anonymous>)
    at rmkidsSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:349:26)
    at rmdirSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:342:7)
    at fixWinEPERMSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:217:5)
    at rimrafSync (C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:319:28)
    at C:\Program Files\nodejs\node_modules\npm\node_modules\rimraf\rimraf.js:350:5
    I am using Typescript, Vue 3 and mySQL (package.json) attached. This is the second time I ran the command, but I got similar results the first time, just it build the DB in mySql first that time. I have attached the Debug Log. At the end it seems to be saying that it is unable to access a dll
    'C:\\Users\\david\\Documents\\My-Computing-Projects\\Vue-Prisma\\test-proj01\\node_modules\\prisma\\query_engine-windows.dll.node'
    This file does not seem to exist. Does anybody have any thoughts on what is going on here? Thanks in advance
    package.json2021-09-25T13_13_32_941Z-debug.log
    r
    • 2
    • 3
  • j

    Josef Henryson

    09/27/2021, 4:02 PM
    Is it better to use MySQL 8 than 5.7 when migrating to Prisma 3?
  • j

    John Peña

    09/27/2021, 7:47 PM
    copying this question in here from #prisma-client https://prisma.slack.com/archives/CCWDULGUW/p1632772029117900
  • j

    John Peña

    09/27/2021, 7:48 PM
    just deployed a very simple change (added a new value to an enum) and we started seeing a bunch of these errors ^^
  • n

    Nick Foden

    09/29/2021, 2:40 AM
    Following steps to go from v2 -> v3 and then running
    prisma migrate dev
    errored, but seems it is somewhat applied and now I have a drift scenario and a schema annotated with these new foreign keys etc. Is there command to rollback last migration on database? Been reading the docs and searching around. I can't lose this database. Worst case - thought is to export with mysql workbench or such and then take the platform offline and baseline / seed it with the backup maybe. But that is rough is will be a lot of time.
    r
    d
    • 3
    • 10
  • m

    Mischa

    10/02/2021, 7:15 AM
    I’m on prisma 3.1.1 on darwin, I have
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
    set which seems to fetch me these engines. I am wondering how I get the migration engine for RHEL because I need it for packaging my lambdas
    t
    r
    • 3
    • 23
  • j

    Josef Henryson

    10/06/2021, 7:23 AM
    After introspection my generated schema.prisma file has a lot of this: @db.Char(30) But most examples of the schema I see online does not have this. Should I remove them?
    r
    • 2
    • 3
  • m

    Maciek K

    10/07/2021, 11:35 AM
    Hello. I was doing the migration path from 2.x to 3.x. With the Named Constraits upgrade I took the second option (I want to use Prisma's default constraint and index names). So I did
    npx prisma migrate dev
    on my development branch and db. When doing the
    npx prisma migrate deploy
    against staging environemtn it errored out on this part
    Copy code
    Database error:
    ERROR: relation "User.email_unique" does not exist
    So exactly on this sql statement:
    Copy code
    -- RenameIndex
    ALTER INDEX "User.email_unique" RENAME TO "User_email_key";
    From schema.prisma:
    Copy code
    model User {
      //deleted unnecessary stuff
      email            String       @unique
    }
    So only then I did notice the text at the bottom (Dealing with cases where more than one database environment is used for the same application). 🤕 So I have pulled schemas from other database environments and I have a problem, because they do differ indeed. In example on production the index does not have the name
    User.email_unique
    , but:
    Copy code
    model User {
    
      email            String       @unique(map: "booking-production$prod.User.email._UNIQUE")
    
    }
    It has also the postgres schema name prepended (!). So what should I do now? I would also very much like to use the default Prisma 3 naming convention for all environments (
    User_email_key
    )?
    r
    t
    f
    • 4
    • 28
  • s

    Sam

    10/10/2021, 9:02 PM
    With Prisma migrate. If I create a channel in my local dev instance. Should I create it in the database, then run prisma db pull. Then create a migration. Or should I change my schema manually instead?
    r
    • 2
    • 3
  • k

    KATT

    10/11/2021, 9:49 AM
    hello! I want to add a CI-job to make sure no schema changes have been done without corresponding migration files have been added. Had a near-miss today where we could’ve borked a whole table. Is there a command I can run that can check if the current db schema is up-to-date with the current schema? similar to how
    migrate dev
    works where it prompts you but I just want to make sure no schema changes are checked in without the migration files
    r
    j
    • 3
    • 10
  • j

    Josef Henryson

    10/11/2021, 1:50 PM
    I’m migrating from Prisma 1.34 to Prisma 3.2.0 and in my current setup I have several types like “XxxWhereInput” for my Xxx types… When I generate types with nexus-prisma I get the type Xxx from my prisma model, but not associated WhereInput etc. Should I add these to my Prisma model to have them generated for nexus? Or should I declare them myself in nexus schema directly? Or can I have them generated in some other way?
    • 1
    • 1
  • t

    Tyler Bell

    10/15/2021, 9:25 PM
    Hi all, We are running into some prisma migrate issues on our production DB. The issue first started on our development DB when prisma returned the typical “Drift Detected” error. We fixed this by reseting the DB. We attempted to push our latest prisma changes to our prod DB by running
    prisma migrate deploy
    but that too resulted in errors such as this one…
    Copy code
    DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42704"), message: "constraint \"CustomField_memberId_fkey\" of relation \"CustomField\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("tablecmds.c"), line: Some(10987), routine: Some("ATExecDropConstraint") }
    We tried manually fixing the errors one by one, but we didn’t get any where with it. No matter what we did,
    migrate deploy
    would never succeed. That led us to try to start from a clean slate. We tried the following…. 1. we first duplicated our production database for testing purposes. 2. we deleted the
    _prisma_migrations
    table 3. we deleted the
    migrations
    folder 4. we then followed the instructions here on adding prisma to an existing project. a. ran
    prisma pull db
    b. ran
    prisma migrate dev --name initial-migration --create-only
    which resulted in yet another
    Drift detected: Your database schema is not in sync with your migration history.
    message. At this point we are kinda at a loss 😅 Does anyone know a good approach to take here?
    t
    f
    • 3
    • 15
  • m

    Maciek K

    10/19/2021, 12:48 PM
    Hello. I'm just seeking for advice. I need to normalise my model a little bit. I need to go from:
    Copy code
    model Booking {
      id             String         @id @default(cuid()) @db.VarChar(30)
      name           String
      forename       String?
      email          String?
      phone          String?
    }
    to:
    Copy code
    model Booking {
      id             String         @id @default(cuid()) @db.VarChar(30)
      clientId       String
      client         Client         @relation(fields: [clientId], references: [id])
    }
    
    model Client {
      id             String         @id @default(cuid()) @db.VarChar(30)
      name           String
      forename       String?
      email          String?
      phone          String?
      bookings       Booking[]
    }
    I'm asking for the best way to approach this mostly in terms of the whole process and modifying the staging, production databases afterwards. Are there some script examples using prisma to modify the whole database? Couldn't find anything on the Prisma page except the seed scripts. Is there anything else I should consider by doing such normalisation. Any pitfalls I should be aware of? Thank You :)
    r
    • 2
    • 1
  • k

    Korzun

    10/22/2021, 9:44 PM
    I just finished struggling through getting CI based migrations with Prisma and PlanetScale working. I thought it might be helpful to others so I put this together. I hope it’s helpful! https://github.com/Korzun/prisma-migrate-planetscale
    👍 1
  • d

    Dan Borstelmann

    10/31/2021, 6:20 PM
    I'm trying to run migrations on a lambda using this command:
    Copy code
    ./node_modules/prisma/build/index.js migrate deploy --schema=<schema_path>
    I've got it mostly working, however the migration-engine binary doesn't exist in the /prisma directory, only /@prisma/engines. Can anyone help me understand the differences between the binary locations which are in /prisma, /@prisma/engines, and /.prisma and what the best way is to point that script to the migration engine which it can't currently find? Also I can't find a migration-engine-rhel-openssl-1.0.x anywhere, only darwin
  • d

    Dan Borstelmann

    10/31/2021, 7:30 PM
    ok managed to get it working, it's in the docs so that's my bad, if anyone is trying to do this, remember to delete your node_modules before you run this command: https://www.prisma.io/docs/reference/api-reference/environment-variables-reference#cli-binary-targets
    👍 2
  • d

    Dan Borstelmann

    10/31/2021, 7:30 PM
    Otherwise it won't pick up the new engines
  • d

    Dan Borstelmann

    10/31/2021, 7:31 PM
    Unless I just got unlucky for some reason
  • s

    SKhan

    11/10/2021, 9:54 AM
    Hey guys, I am struggling to fix a migration issue and tried all the advice on the https://pris.ly/d/migrate-resolve link. I am trying to update my db with the latest pulled migrations (from repo). However, Prisma is stuck on a particular migration. I tried: • Resetting the db (its dev env. so its ok for now)| • Tried the
    rolled-back
    command and then then the
    migrate dev
    /
    migrate reset
    again, to no success The errors I am getting are: • for `migrate reset`:
    Copy code
    Error: P3018
    
    A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    
    Migration name: 20210722071621_updated_enum_activity_type_to_include_invite_and_message
    
    Database error code: 25001
    
    Database error:
    ERROR: ALTER TYPE ... ADD cannot be executed from a function or multi-command string
    
    DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("25001"), message: "ALTER TYPE ... ADD cannot be executed from a function or multi-command string", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("xact.c"), line: Some(3237), routine: Some("PreventTransactionChain") }
    • for
    rolled back
    and then `migrate dev`:
    Copy code
    Error: P3006
    
    Migration `20210722071621_updated_enum_activity_type_to_include_invite_and_message` failed to apply cleanly to the shadow database. 
    Error:
    db error: ERROR: ALTER TYPE ... ADD cannot be executed from a function or multi-command string
       0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
                 at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:373
       1: sql_migration_connector::validate_migrations
                 at migration-engine/connectors/sql-migration-connector/src/lib.rs:317
       2: migration_core::api::DevDiagnostic
                 at migration-engine/core/src/api.rs:89
    How to resolve this?
    f
    j
    • 3
    • 8
  • m

    Mischa

    11/11/2021, 5:16 PM
    any idea what would cause a migration to randomly try to rename all of my indexes?
    m
    f
    • 3
    • 9
  • a

    Adam

    11/16/2021, 6:12 PM
    I had a migration fail, but there wasn’t any useful log in the console. and the
    logs
    column of
    _prisma_migrations
    is empty. Is there someplace I can see the error?
    r
    • 2
    • 1
  • p

    Pierre Ortega

    11/18/2021, 7:41 PM
    can anyone guide me in how apply migrations on a big postgres database (10M~ rows)
    k
    j
    • 3
    • 2
  • c

    Chris Bitoy

    11/24/2021, 5:57 PM
    🙋 Roll call! Who else is here?
    🖐️ 5
    prisma rainbow 3
  • f

    Frederik

    12/03/2021, 1:39 PM
    Dear Prisma devs 👋 We are often asked for rollbacks to mitigate failed migrations. We believe automatic rollbacks can be problematic and give a wrong sense of security. Instead, we are thinking about exposing some of the internal primitives of migrate. This would give developers the tools needed to resolve failed migrations forward or backwards. If this sounds interesting, please take a look at the proposal and give us some feedback: https://github.com/prisma/prisma/issues/10561 prisma rainbow Thanks!
    👍 1
    👀 2
  • c

    Chris Bitoy

    12/06/2021, 5:35 PM
    Happy Monday y’all, hoping to get help creating an entry using Post request. The error I am getting is:
    Copy code
    → 42   const creatives = await prisma.creative.create({
             data: {
               brandLogo: 'www.test2.png',
               brandName: 'This is a Unique one',
               projectName: 'ProjectName is also unique',
               headerImage: 'www.imageheader.png',
               projectCreative: [
                 '<http://anothertest2.com|anothertest2.com>',
                 '<http://anothertest3.com|anothertest3.com>',
                 '<http://anothertest4.com|anothertest4.com>',
                 '<http://anothertest5.com|anothertest5.com>'
               ]
               ~~~~~~~~~~~~~~~~~~~~~
             }
           })
    
    Argument projectCreative: Got invalid value 
    [
      '<http://anothertest2.com|anothertest2.com>',
      '<http://anothertest3.com|anothertest3.com>',
      '<http://anothertest4.com|anothertest4.com>',
      '<http://anothertest5.com|anothertest5.com>'
    ]
    on prisma.createOneCreative. Provided List<String>, expected ProjectCreativeCreateNestedManyWithoutCreativeInput:
    type ProjectCreativeCreateNestedManyWithoutCreativeInput {
      create?: ProjectCreativeCreateWithoutCreativeInput | List<ProjectCreativeCreateWithoutCreativeInput> | ProjectCreativeUncheckedCreateWithoutCreativeInput | List<ProjectCreativeUncheckedCreateWithoutCreativeInput>
      connectOrCreate?: ProjectCreativeCreateOrConnectWithoutCreativeInput | List<ProjectCreativeCreateOrConnectWithoutCreativeInput>
      createMany?: ProjectCreativeCreateManyCreativeInputEnvelope
      connect?: ProjectCreativeWhereUniqueInput | List<ProjectCreativeWhereUniqueInput>
    }
    But I defined my models to accept an array of strings:
    Copy code
    model Creative {
      id              Int               @id @default(autoincrement())
      owner_id        String            @default(cuid())
      campaign_id     String            @default(cuid())
      parent_c_id     String            @default(cuid())
      brandLogo       String
      brandName       String            @unique
      projectName     String            @unique
      headerImage     String
      projectCreative ProjectCreative[]
      createdAt       DateTime          @default(now())
      updatedAt       DateTime          @updatedAt
    }
    
    model ProjectCreative {
      id              Int       @id @default(autoincrement())
      creative        Creative? @relation(fields: [creativeId], references: [id])
      creativeId      Int?
      cloudinary_url0 String
      cloudinary_url1 String
      cloudinary_url2 String
      cloudinary_url3 String
      createdAt       DateTime  @default(now())
      updatedAt       DateTime  @updatedAt
    }
    via my POST route:
    Copy code
    <http://router.post|router.post>("/creatives", async (req, res) => {
      try {
        const { brandLogo, brandName, projectName, headerImage, projectCreative } =
          req.body;
        const creatives = await prisma.creative.create({
          data: { brandLogo, brandName, projectName, headerImage, projectCreative },
        });
        res.status(201).json({ success: true, data: creatives, error: "" });
      } catch (error) {
        console.log(error);
        res.status(500).json({ data: {}, error: error, status: 500 });
      }
    });
    With this test data:
    Copy code
    {
      "brandLogo": "www.test2.png",
      "brandName": "This is a Unique one",
      "projectName": "ProjectName is also unique",
      "headerImage": "www.imageheader.png",
      "projectCreative": [
        "<http://anothertest2.com|anothertest2.com>",
        "<http://anothertest3.com|anothertest3.com>",
        "<http://anothertest4.com|anothertest4.com>",
        "<http://anothertest5.com|anothertest5.com>"
      ]
    }
    Can you help me figure it out?
  • l

    Luis Alfredo Lorenzo

    12/06/2021, 8:00 PM
    Hello! Does someone knows if it's possible to disable transactions for a particular migration? I would like to build an index concurrently, but it's not possible to build it inside a transaction on PostgreSQL.
    Copy code
    Database error code: 25001
    
    Database error:
    ERROR: CREATE INDEX CONCURRENTLY cannot run inside a transaction block
    👀 1
    j
    r
    +2
    • 5
    • 15
  • b

    Barnaby

    12/07/2021, 12:36 PM
    Hey I'm running into an error I've never seen before during migrate, the UUID function is missing according to Prisma but it's installed and available in Postgres
  • b

    Barnaby

    12/07/2021, 12:38 PM
    Copy code
    Migration `20211207122745_genesis` failed to apply cleanly to the shadow database. 
    db error: ERROR: function uuid_generate_v4() does not exist
    And:
    Copy code
    postgres=# select uuid_generate_v4();
               uuid_generate_v4           
    --------------------------------------
     1c68bfd5-f682-498c-a9b9-59b79ddcfa26
    (1 row)
    what is meant by "shadow database", is this not my maintenance database? Does the uuid function actually need to be "installed" in each individual database?
    n
    • 2
    • 3
  • b

    Barnaby

    12/07/2021, 12:41 PM
    https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/enable-native-database-functions found the docs!
  • b

    Barnaby

    12/07/2021, 12:41 PM
    The error should definitely link here
1...56789Latest