https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • h

    Henrique Aurelio

    05/03/2022, 7:06 PM
    I have an authentication table and users table with one-one relationship and i did with findMany and is but i found some strange because i need to be unique in my database and with findUnique doesnt work with is
    a
    • 2
    • 8
  • z

    Zak

    05/03/2022, 7:51 PM
    Hi Prisma Family, I cannot seem to create a new project on Prisma Data Platform, clicking the ‘New Project’ button doesn’t do anything. Anyone know how to resolve this?
    n
    • 2
    • 3
  • j

    Junior-Web-Dev

    05/03/2022, 8:13 PM
    Hello, Im having a very hard time creating this SQL statement with Prisma. Would anyone know how it can be done?
    Copy code
    SELECT *
    FROM "token"
    INNER JOIN "user" u on u.user_id = token.user_id
    WHERE u.email = '<mailto:abc@abc.com|abc@abc.com>'
  • j

    Junior-Web-Dev

    05/03/2022, 8:17 PM
    actually im trying to update instead of select
  • j

    Junior-Web-Dev

    05/03/2022, 8:23 PM
    i tried this:
    Copy code
    await prisma.token.update({
        data: {
            user: {
                connectOrCreate: {
                    where: {
                        email: user.email
                    },
                    create: {
                        token: user.token
                    }
                }
            }
        },
        include: {
            user: true
        }
    })
    The logic is update "token" column where "user_id" is fk to "user" table...find "token" based off "email" in "user" table... hope it makes sense
    j
    • 2
    • 2
  • j

    Junior-Web-Dev

    05/03/2022, 9:07 PM
    im not sure whats wrong with my logic here.. so i dont have any records in my token table so far... using upsert should find record if it exists where user_id = 1 If it finds row with user_id = 1 then it should update the token column.. if it doesnt exist, then create: { user_id and token } and insert
    await prisma.token.upsert({
    where: {
    'user_id': dbUser.user_id
    },
    data: {
    'token': refreshToken
    },
    create: {
    'user_id': dbUser.user_id,
    'token': refreshToken
    }
    });
  • j

    Junior-Web-Dev

    05/03/2022, 9:09 PM
    wrapping my prisma.table.update() (and all other CRUD calls) with try and catch just gives me client version when i output catch error. whats the recommended way
  • j

    Junior-Web-Dev

    05/03/2022, 9:13 PM
    is it possible to just throw in SQL statements instead of using this json mannerism? got a coworker whose using this plugin and its extremely difficult for me. pure SQL works for me but would still like to use the prisma schema for his sake. is it possible?
    j
    • 2
    • 2
  • j

    Junior-Web-Dev

    05/03/2022, 9:18 PM
    awesome thanks so much!
    v
    • 2
    • 7
  • l

    Luke Morris

    05/03/2022, 11:47 PM
    Hi all -- I'm having trouble following the guide for the expand-contract pattern in the context of a rolling deploy where two versions of my prisma client are running at the same time. Steps 1-6 work just fine, but Step 7 asks me to remove a column from my schema. When I do that, the new prisma client expects the column to be removed whereas the old prisma client expects the column to be present. During the rolling deploy, code reliant on the old prisma client will throw errors, even if I don't refer to that column anywhere in my code. I'm guessing because it's performing a
    SELECT *
    , and trying to map column values into required fields in the resulting JS object. Any advice on what to do here? Is there a way for me to exclude a field from my prisma client without modifying the underlying database schema?
    j
    • 2
    • 18
  • j

    Jason Kleinberg

    05/04/2022, 12:56 AM
    Has anyone else had problems with
    @db.Decimal(XX, 5)
    ? For some reason when I set my data to 5 decimal places, the values come out like
    12.000000000000002
    . Not only is it adding a float rounding error, they have too many decimal places. Setting it to 2,3,4,and 6 work fine. I haven’t checked above that point.
    j
    n
    • 3
    • 12
  • s

    Slackbot

    05/04/2022, 8:38 AM
    This message was deleted.
    a
    a
    • 3
    • 6
  • a

    Alfred Noland

    05/04/2022, 9:06 AM
    Hi building a home application. We have Home model { id name String } and Facility { id name String } The facilities are fixed and will be unversal for all homes. Example Pool, Kithcen, Shower etc. The homes can have none or all of the facilites. How should this many to many relationship be setup?
    n
    • 2
    • 1
  • d

    Dominik Jašek

    05/04/2022, 10:57 AM
    Anyone using Webstorm? What do you use to write
    schema.prisma
    ? This plugin really sucks… https://plugins.jetbrains.com/plugin/14240-prisma
    n
    • 2
    • 1
  • a

    alexwasik

    05/04/2022, 11:53 AM
    question on Cascading deletes with SQLite. I have a few models and I if I want to delete a Player, I want all other associated data to be deleted as well
    Copy code
    model Player {
      id        String        @id
      username  String?
      createdAt DateTime      @default(now())
      updatedAt DateTime      @default(now())
      losses    Match[]       @relation("Losses")
      resigned  Match[]       @relation("Resigned")
      wins      Match[]       @relation("Wins")
      moves     Move[]
      matches   PlayerMatch[]
      rolls     Roll[]
      lastLogin DateTime?
    }
    n
    • 2
    • 8
  • l

    Luke Morris

    05/04/2022, 3:39 PM
    Heya, bumping my question from yesterday. I'm having trouble following the guide for the expand-contract pattern in the context of a rolling deploy where two versions of my prisma client are receiving production traffic at the same time. Steps 1-6 work just fine, but Step 7 asks me to remove a column from my schema. When I do that, the new prisma client expects the column to be removed whereas the old prisma client expects the column to be present. During the rolling deploy, code reliant on the old prisma client will throw an error like below, even if I don't refer to that column anywhere in my code. Any advice on what to do here? Is there a way for me to exclude a field from my prisma client without modifying the underlying database schema?
    Copy code
    Invalid `prisma.user.findUnique()` invocation:
      The column `User.removedField` does not exist in the current database.
    n
    • 2
    • 1
  • h

    Hugo Vallejo

    05/04/2022, 4:16 PM
    I'm using prisma proxy and my schema is outdated, is there a way to update it?
    n
    • 2
    • 1
  • b

    Berian Chaiwa

    05/04/2022, 5:00 PM
    Hello fam! Anyone with a good explanation as to why
    contains
    fails to match if filter is the first word of text? E.g., Say
    description="Chaiwa is a good guy"
    , sending
    filter: "guy"
    matches this record but sending
    filter: "chai"
    fails. See implementation of the where clause for the query below:
    Copy code
    const where = args.filter
        ? {
            OR: [
              {
                description: { contains: args.filter },
                url: { contains: args.filter },
              },
            ],
          }
        : {};
    j
    j
    • 3
    • 4
  • o

    Omar

    05/04/2022, 7:15 PM
    Hello all, I'm trying out a prisma generator called
    zod-prisma
    but so far it keeps getting stuck at the generation step. Has anybody here experienced this issue?
    ✅ 1
    n
    • 2
    • 3
  • y

    Yaakov

    05/04/2022, 8:39 PM
    Hi, interactiveTransaction stopped working for me as of Prisma 3.13. I'm getting the following error: `Error: Failed to convert napi
    string
    into rust type `String``
    at Object.transaction (/usr/src/app/node_modules/@prisma/client/runtime/index.js:41312:64)
    at async Proxy._transactionWithCallback (/usr/src/app/node_modules/@prisma/client/runtime/index.js:46414:21)
    Copy code
    model Person {
      id   Int    @id @default(autoincrement())
      name String
    }
    Copy code
    <http://router.post|router.post>('/person', (req, res, next) => {
    
      prisma.$transaction(async (prisma) => {
        const person = await prisma.person.create({
          data: {
            name: 'A new role',
          },
        });
    
        // Do something else
    
        return person;
      }).then(person => res.status(201).json(person))
        .catch(next);
    });
    n
    • 2
    • 2
  • d

    david

    05/04/2022, 11:40 PM
    Greetings, friends - I’m somewhat new to prisma (loving it so far), so this may be a dumb question, but I couldn’t find the answer in the docs or searching for it. I’m trying to add null values to an integer array in Postgres. I have a simple model defined as
    Copy code
    model foo {
      id   String     @id
      bar Int[]
    }
    when I have:
    bar = [0, 0]
    and call
    Copy code
    prisma.foo.create({
      data: {
        bar
      },
    the array is saved in the database, but when I try to set one of the values to null
    bar = [null, 0]
    I get a vague error
    failed: {"clientVersion":"3.12.0"}
    I tried turning on extra debug logging, but I’m not getting any useful info. I can also directly update the row directly in postgres without any issues ( … set bar = ‘{null,0}’) Is it possible to set null values in an integer array through prisma? I appreciate any help you can provide.
    j
    • 2
    • 5
  • j

    Jawad Sefiani

    05/05/2022, 12:28 AM
    Hi everyone,
    prisma migrate dev
    is overwriting a custom migration that I wrote to alter one of my tables, this is the custom SQL script (I first created an empty migration using --create-only):
    Copy code
    -- AlterTable
    ALTER TABLE "menu-item-translations"
    DROP CONSTRAINT "menu-item-translations_menuItemId_fkey",
    ADD CONSTRAINT "menu-item-translations_menuItemId_fkey"
    FOREIGN KEY ("menuItemId") REFERENCES "menu-items"("id") ON DELETE CASCADE ON UPDATE CASCADE;
    After that I ran
    prisma migrate dev
    but it creates another migration (which i don't want because it removes the cascade behavior, idk why Prisma is doing this???):
    Copy code
    -- DropForeignKey
    ALTER TABLE "menu-item-translations" DROP CONSTRAINT "menu-item-translations_menuItemId_fkey";
    
    -- AddForeignKey
    ALTER TABLE "menu-item-translations" ADD CONSTRAINT "menu-item-translations_menuItemId_fkey" FOREIGN KEY ("menuItemId") REFERENCES "menu-items"("id") ON DELETE SET NULL ON UPDATE CASCADE;
    n
    • 2
    • 1
  • y

    Yerzhan

    05/05/2022, 1:01 AM
    hi there, can someone please help with a few concerns? 1. what’s the best way to track migration history? a. based on the official documentation https://www.prisma.io/docs/concepts/components/prisma-migrate#migration-history, we have list of files in
    migrations
    folder +
    _prisma_migrations
    table. it’s kind of ok for working on migrations for 1 person. but, did anyone face any problems with creating a few migrations in 10 PRs? which PR’s migration will go first when we merge? how do you handle the migration history in that case? b. how to make sure that version control work as it expected? for example when 5 engineers works on the same table and created a few PRs that will somehow affect the same table? 2. how to rollback? a. how do we rollback the latest local migration? b. how do we rollback to the specific migration? 3. how to catch migration errors? a. what happened if some migration fails? how do we know and fix it? thanks!
    n
    • 2
    • 1
  • d

    Devan Benz

    05/05/2022, 1:37 AM
    Is this the best place to ask questions regarding prisma? Or is there a help channel devoted to that?
    j
    v
    • 3
    • 2
  • d

    Devan Benz

    05/05/2022, 1:46 AM
    I’m trying to build a POC for work and translate an already existing MongoDB document schema into my
    schema.prisma
    file. So far it seems relatively straight forward but I have one field that is using a Record utility type in typescript. It’s type is
    Record<string, string | number | boolean | null | undefined>
    is there a way to translate this into prisma’s schema file?
    n
    • 2
    • 2
  • c

    Codingbutter llc

    05/05/2022, 2:59 AM
    Hi!! how is everyone
    👋 3
    n
    • 2
    • 1
  • j

    Jawad Sefiani

    05/05/2022, 12:32 PM
    Does anyone know why Prisma tries to overwrite my custom migration script? This looks like a bug to me.
    n
    • 2
    • 2
  • j

    Jonathan

    05/05/2022, 1:18 PM
    Hi folks, we are running into various jest problems with our prisma. It seems each test-file is creating a new instance of prisma, leading to a major heap size after a while. The prisma instances do not seem to be closed or removed either. Since we can’t share globals in jest (meaning we can’t have a single instance of prisma), did anyone experience this, and figure out a way to circumvent this problem? Example of a jest file:
    Copy code
    // Intantiation class in a /src/utils/makeTestPrisma.ts
    export const makeTestPrisma = () => {
        if (process.env.NODE_ENV === 'test') {
          const prisma = global.testPrisma || new PrismaClient({
            datasources: { postgresql: { url: 'OUR_URL' } },
          });
      
          global.testPrisma = prisma;
      
          return prisma;
        }
      
        throw new Error('Not possible; only works in Test environment!');
      }
    
    
    // In a test file, /src/Users/User.test.ts
    
    const prisma = makeTestPrisma();
    
    test(async () => {
       const res = await services.doSomeStuffInDb(prisma);
    
       expect(res.users).toEqual(2);
    });
    a
    d
    • 3
    • 4
  • o

    Omar

    05/05/2022, 3:46 PM
    👋 Hello, team!
    n
    • 2
    • 1
  • m

    Mathie

    05/05/2022, 4:39 PM
    Hello ! My model :
    model Response {
    id       Int      @id @default(autoincrement())
    survey   Survey   @relation(fields: [surveyId], references: [id])
    surveyId Int
    user     User     @relation(fields: [userId], references: [id])
    userId   Int
    sendAt   DateTime @default(now())
    json     Json
    }
    How to use findUnique on the field user ? I want to get the user with the ID 1
    r
    y
    • 3
    • 4
1...570571572...637Latest