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

    ludovic

    01/20/2022, 12:48 PM
    Hello everyone, I am running a few apps in production using Prisma, all versions are between 2.30.3 and 3.6.0. I had multiple time this problem, the error is : Error in PostgreSQL connection: Error { kind: Closed, cause: None } Once this error happen, only restarting the server can fix it. Prisma can't fetch new connections and all query to the database fail, the server will stay faulty until next restart There are a few related issues on github : https://github.com/prisma/prisma/issues/6329#issuecomment-815012006 the issue is due to Prisma or to the database ? I have a few managed postgres database hosted on DigitalOcean and other platform, but I have the error on all of them. Is there a way to fix this ? In the issue there is some talk about a middleware to retry the connections if one is faulty, is this recommended ?
  • a

    Alex Vilchis

    01/20/2022, 5:02 PM
    Hi, guys đŸ‘‹đŸ» I am doing a rename of a table with Prisma Migrate. I understand I need to customize this migration but I don't know how I should rename the foreign keys and indexes. Is there any convention I should adhere to?
    s
    • 2
    • 6
  • s

    Sean Huggins

    01/21/2022, 6:40 AM
    Hey!
  • s

    Sean Huggins

    01/21/2022, 6:43 AM
    I just started using prisma, it's pretty awesome! I was looking into the full-text-search features. Does Prisma have support for Postgres partial string FTS? (eg.
    ca:*
    -> cat, car, can, Canada, cats, catastrophic, etc....)
  • s

    Sean Huggins

    01/21/2022, 6:44 AM
    also ranking of searches?
  • s

    Sean Huggins

    01/21/2022, 6:44 AM
    It's really important for my use case so I want to make sure Prisma is the right choice!!
  • s

    Sean Huggins

    01/21/2022, 6:44 AM
    but it's pretty awesome so far, the
    .prisma
    schema file is so pretty
  • k

    Ki Hong

    01/21/2022, 7:06 AM
    Hi all, I'm having problem defining a relation where it involves multi-fields composite ID and its references coming from multiple table:
    Copy code
    model PostLevel {
      postLevelCode String
      countryCode   String
      languageCode  String
      postLevelName String
    
      @@id([postLevelCode, countryCode, languageCode])
      @@unique([postLevelCode, countryCode, languageCode])
    }
    
    model Profile {
      id          String @id
      countryCode String
      user        User?
    }
    
    model User {
      id           String  @id
      languageCode String
      profileId    String
      profile      Profile @relation(fields: [profileId], references: [id])
      posts        Post[]
    }
    
    model Post {
      id            String    @id
      postedById    String
      postedBy      User      @relation(fields: [postedById], references: [id])
      postLevelCode String
      postLevel     PostLevel @relation(fields: [postLevelCode], references: [postLevelCode, countryCode, languageCode])
    }
    I want to be able to resolve
    postLevelName
    when I query
    Post
    . **ps: This is an existing and production DB where DB migration should be avoided at all cost. This can be solved by using
    $queryRaw
    and
    INNER JOIN
    but that would defeat the purpose of using this great ORM. Im getting these errors:
  • s

    Sean Huggins

    01/21/2022, 8:22 AM
    Another question, I have a bunch of data for my app that I always need there, so my thoughts are to put the data inside of my seeder. The problem is, it's quite a chore to create the seed data, since I have a lot of relational data, many-to-many relationships etc... Is there an easier way for me to create seeder data? Can generate a seeder file, based on the data that's in my db already? Would love for some ideas! Thanks
  • u

    user

    01/21/2022, 11:19 AM
    Prisma Meetup Online #9 : Remix edition + a raffle! 🎁

    https://www.youtube.com/watch?v=D5XIMOzm3YEâ–Ÿ

    Join us for a very special edition of the Prisma Meetup, where we talk about all things Remix. This full-stack web framework has taken the tech world by the storm - let's take a deep dive into its features and see how it fits into Prisma ecosystem as well! Our superstar speakers: ⭐Chance Strickland (@chancethedev) - TBA ⭐Austin Crim (@crim_codes) - "Up and Running with Remix and the Prisma Data Proxy" ⭐Alex Anderson (@ralex1993) - "Wrecking Remix Resource Routes" During this event, we will host a raffle, where you can win a full ticket to Node Congress (https://nodecongress.com/).
  • s

    Shmuel

    01/21/2022, 4:17 PM
    Hi. The primsa docs mention the ability to update many related records like this...
    Copy code
    const update = await prisma.user.update({
      where: {
        id: 6,
      },
      data: {
        posts: {
          updateMany: {
            where: {
              published: true,
            },
            data: {
              published: false,
            },
          },
        },
      },
    })
    In this case all posts that match the where clause will be updated to
    published: false
    I would like to know if it's possible to do an
    updateMany
    without passing a
    where
    clause. Rather passing in a bunch of objects to the
    data
    property and prisma will know which records to update based on the unique key which will be in each object. Like this...
    Copy code
    const update = await prisma.user.update({
      where: {
        id: 6,
      },
      data: {
        posts: {
          updateMany: {
            data: [
              { id: 5, published: false }, { id: 6, published: true }
            ],
          },
        },
      },
    })
  • y

    Yaakov

    01/21/2022, 5:48 PM
    Hi, is there a way to define a one-to-one relation based on 2 fields? I'd like to relate the
    User
    and
    InternalUserProfile
    only when
    User.type = INTERNAL
    .
    Copy code
    model User {
      id                  Int                  @id @default(autoincrement())
      type                UserType
      internalUserProfile InternalUserProfile?
    }
    
    model InternalUserProfile {
      user   User @relation(fields: [userId = User.id AND User.type = 'INTERNAL'], references: [id])
      userId Int
    }
    
    enum UserType {
      INTERNAL
      EXTERNAL
    }
  • s

    Simon BrÀnnström

    01/21/2022, 6:05 PM
    Does anyone have issues with using NestJS + Prisma + Docker (compose) + Macbook M1? I can't get the connection to the database to work. Feels like I've tried everything by now.... The setup works fine on non-M1 computers. Attached the error messages. Any advice would be appreciated :)
    • 1
    • 1
  • a

    Alex Vilchis

    01/21/2022, 6:21 PM
    Hey, guys, what is the best way to generate a crud that uses Prisma with Nexus?
    l
    • 2
    • 1
  • a

    Andy Bustamante

    01/21/2022, 9:08 PM
    Hi all - Is it still not possible to use an upsert without defining value for where? I have an example where sometimes the id is not known.
    Copy code
    context.prisma.model.upsert({
          where: { id: undefined },
          update: args.data,
          create: args.data,
        })
    t
    • 2
    • 5
  • m

    maxd

    01/22/2022, 1:15 AM
    Hi all, is it normal for the client to return errors that only have clientVersion field? Because there is no client error type that only has clientVersion and nothing else.
  • m

    maxd

    01/22/2022, 1:17 AM
    this is the raw response from an upsert query:
    {"error":{"clientVersion":"3.5.0"}}
  • k

    Kelly Copley

    01/22/2022, 3:52 AM
    I'm running an upsert on my users table and I get this quite ambiguous error,
    Null constraint violation on the (not available)
    . I'm not sure why it says
    (not available)
    or what that means.. As far as I can tell there isn't anything null within the object passed to the create method. Schema is as follows:
    Copy code
    model User {
      id            String       @id @default(uuid())
      email         String?      @unique
      emailVerified DateTime?
      isPresenter   Boolean      @default(false)
      bio           String?      @db.LongText
      cellPhone     String?
      homePhone     String?
      firstName     String?
      middleName    String?
      lastName      String?
      permissions   Permission[]
      street        String?
      unit          String?
      city          String?
      state         State?
      zip           String?
      createdAt     DateTime     @default(now())
      updatedAt     DateTime     @updatedAt
      tickets       Ticket[]
      sessions      Session[]
      orders        Order[]
    }
    And the code for the upsert:
    Copy code
    const user = await prisma.user.upsert({
      where: { email: '<mailto:your.email+fakedata47684@gmail.com|your.email+fakedata47684@gmail.com>' },
      update: {},
      create: {
        email: '<mailto:your.email+fakedata47684@gmail.com|your.email+fakedata47684@gmail.com>',
        firstName: 'Stan',
        lastName: 'Schamberger',
        street: '2100 Maymie Bridge',
        city: 'Stromanport',
        state: 'OR',
        zip: '17083'
      }
    });
    As you can see every field in the schema besides relation fields, is either optional or have defaults set, which makes me wonder which constraint is failing.
    z
    • 2
    • 2
  • z

    Zhen

    01/22/2022, 4:37 AM
    Hi all, does anyone have any experience getting prisma 3's files into a lambda layer? I have tried this and I am getting this error when I generate with the rhel target in my cicd pipeline and then use prismaLayer as my layer path:
    "prismaLayer\nodejs\node_modules\.prisma\libquery_engine-rhel-openssl-1.0.x.so.node"
    Copy code
    "Error: Query engine library for current platform \"rhel-openssl-1.0.x\" could not be found.",
                "You incorrectly pinned it to rhel-openssl-1.0.x",
                "",
                "This probably happens, because you built Prisma Client on a different platform.",
                "(Prisma Client looked in \"/var/task/src/libquery_engine-rhel-openssl-1.0.x.so.node\")",
                "",
                "Searched Locations:",
                "",
                "  /.prisma/client",
                "  /home/runner/work/.../node_modules/@prisma/client",
                "  /var/task",
                "  /var/task/node_modules/.prisma/client",
                "  /var/task/node_modules/.prisma/client",
                "  /tmp/prisma-engines",
                "  /var/task/node_modules/.prisma/client",
                "",
                "You already added the platform \"rhel-openssl-1.0.x\" to the \"generator\" block",
                "in the \"schema.prisma\" file as described in <https://pris.ly/d/client-generator>,",
                "but something went wrong. That's suboptimal.",
                "",
  • z

    Zhen

    01/22/2022, 4:37 AM
    any help is appreciated!
  • j

    james milord

    01/22/2022, 6:38 AM
    Hi everyone, hoping someone can help me here I have the following tables
    customers
    and
    stores
    which I define in my
    schema.prisma
    file like this
    Copy code
    model Customer {
      id                     BigInt         @id @default(autoincrement())
      email                  String         @db.VarChar(255)
      encrypted_password     String
      first_name             String?        @default("") @db.VarChar(255)
      last_name              String?        @default("") @db.VarChar(255)
      reset_password_sent_at DateTime?
      reset_password_token   String?        @db.VarChar(16)
      status                 CustomerStatus @default(ACTIVE)
      created_at             DateTime       @default(now())
      updated_at             DateTime       @updatedAt
      store                  Store          @relation(fields: [store_id], references: [id])
      store_id               BigInt
    
      @@index([email, store_id])
      @@index([reset_password_token])
      @@index([email])
      @@index([store_id])
    
      @@map("customers")
    }
    
    model Store {
      id                 BigInt     @id @default(autoincrement())
      customer           Customer[]
      domain             String     @default("") @db.VarChar(255)
      locale             Locale     @default(US)
      region             String?    @db.VarChar(255)
      sender             String     @default("") @db.VarChar(255)
      shopify_store_name String?    @db.VarChar(255)
      created_at         DateTime   @default(now())
      updated_at         DateTime   @updatedAt
    
      @@map("stores")
    }
    
    enum CustomerStatus {
      ACTIVE      @map("active")
      ACTIVATING  @map("activating")
    }
    
    enum Locale {
      US  @map("en-US")
      UK  @map("en-GB")
    }
    after running
    npx prisma migrate dev --name  <migration name>
    I get the following sql migration migration file output
    Copy code
    /*
      Warnings:
    
      - You are about to drop the `customer` table. If the table is not empty, all the data it contains will be lost.
    
    */
    -- CreateEnum
    CREATE TYPE "CustomerStatus" AS ENUM ('active', 'activating');
    
    -- CreateEnum
    CREATE TYPE "Locale" AS ENUM ('en-US', 'en-GB');
    
    -- DropTable
    DROP TABLE "customer";
    
    -- CreateTable
    CREATE TABLE "customers" (
        "id" BIGSERIAL NOT NULL,
        "email" VARCHAR(255) NOT NULL,
        "encrypted_password" TEXT NOT NULL,
        "first_name" VARCHAR(255) DEFAULT E'',
        "last_name" VARCHAR(255) DEFAULT E'',
        "reset_password_sent_at" TIMESTAMP(3),
        "reset_password_token" VARCHAR(16),
        "status" "CustomerStatus" NOT NULL DEFAULT E'active',
        "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
        "updated_at" TIMESTAMP(3) NOT NULL,
        "store_id" BIGINT NOT NULL,
    
        CONSTRAINT "customers_pkey" PRIMARY KEY ("id")
    );
    
    -- CreateTable
    CREATE TABLE "stores" (
        "id" BIGSERIAL NOT NULL,
        "domain" VARCHAR(255) NOT NULL DEFAULT E'',
        "locale" "Locale" NOT NULL DEFAULT E'en-US',
        "region" VARCHAR(255),
        "sender" VARCHAR(255) NOT NULL DEFAULT E'',
        "shopify_store_name" VARCHAR(255),
        "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
        "updated_at" TIMESTAMP(3) NOT NULL,
    
        CONSTRAINT "stores_pkey" PRIMARY KEY ("id")
    );
    
    -- CreateIndex
    CREATE INDEX "customers_email_store_id_idx" ON "customers"("email", "store_id");
    
    -- CreateIndex
    CREATE INDEX "customers_reset_password_token_idx" ON "customers"("reset_password_token");
    
    -- CreateIndex
    CREATE INDEX "customers_email_idx" ON "customers"("email");
    
    -- CreateIndex
    CREATE INDEX "customers_store_id_idx" ON "customers"("store_id");
    I was looking for the foreign key
    store_id
    on the
    customers
    table to have a constraint clause like the following
    Copy code
    CONSTRAINT FOREIGN KEY ("store_id") REFERENCES "public"."stores" (id)
    I have been unsuccessful so far and all I want is for the
    store_id
    to be a foreign key that references the store
    id
    .
    • 1
    • 1
  • k

    Kelly Copley

    01/22/2022, 7:31 AM
    Currently running into this error:
    Copy code
    Query interpretation error. Error for binding '6': Error occurred during query execution:
    InterpretationError("Unable to convert expression result into a set of selection results", None)
    Any help appreciated.
  • r

    Raj Chaudhary

    01/22/2022, 12:29 PM
    My prisma schema is as follows: generator client { provider = "prisma-client-js" binaryTargets = ["native", "rhel-openssl-1.0.x"] } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model Account { id BigInt @id createdAt DateTime @db.Timestamptz(3) @default(now()) updatedAt DateTime @db.Timestamptz(3) @updatedAt name String users _User_[] } model User { id BigInt @id createdAt DateTime @db.Timestamptz(3) @default(now()) updatedAt DateTime @db.Timestamptz(3) @updatedAt accountId BigInt account Account @relation(fields: [accountId], references: [id]) fullName String email String oauthToken String? } The generated sql file is as follows: -- CreateTable CREATE TABLE "Account" ( "id" BIGINT NOT NULL, "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMPTZ(3) NOT NULL, "name" TEXT NOT NULL, CONSTRAINT "Account_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "User" ( "id" BIGINT NOT NULL, "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMPTZ(3) NOT NULL, "accountId" BIGINT NOT NULL, "fullName" TEXT NOT NULL, "email" TEXT NOT NULL, "oauthToken" TEXT, CONSTRAINT "User_pkey" PRIMARY KEY ("id") ); -- AddForeignKey ALTER TABLE "User" ADD CONSTRAINT "User_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE RESTRICT ON UPDATE CASCADE; However prisma client does not mark the User.oauthToken as nullable in TS. Can anyone help?
  • d

    Dan Shapir

    01/22/2022, 2:06 PM
    Include with conditions - I couldn't find a way to do a job with a condition. Let's assume I have entity A and B, I want to load all entities A, and their corresponding B entites where B.field equals A.otherField. This is basically impossible. Just a simple Select * from A Inner join B on a.bid = b.id and a.field > b.field For example
  • s

    Shoki I

    01/22/2022, 3:32 PM
    Hi! Is there the best way to transfer the data when changing the models? I want to divide a model into three. However, the problem is that the system is already running with using the First Model and some data is stored in Model A of the First Model. So when I try to migrate, all the data in the First Model will be lost. If there is a good way to transfer the stored data to the Updated Model, I’d like to know. Thank you.
    Copy code
    First Model
    Model A
     id
     name
     email
     description
     value1
     value2
     value3
    ↓
    Copy code
    Updated Model
    Model A
     id
     name
    
    Model B
     modelA_id
     modelB_id
     value
    
    Model C
     id
     description
     label
  • t

    Tomer Aberbach

    01/22/2022, 5:00 PM
    Hey everyone! I had a question about wrapping Prisma functions in TypeScript. I'm trying to write the following function:
    Copy code
    export async function findUserByEmailAndPassword<
      Select extends Prisma.UserSelect,
    >({ email, password }: UserData, select: Subset<Select, Prisma.UserSelect>) {
      const user = await findUserByEmail(email, { ...select, passwordHash: true })
    
      if (!user) {
        return null
      }
    
      const { passwordHash, ...userWithoutPasswordHash } = user
    
      if (!(await compareHash(password, passwordHash))) {
        return null
      }
    
      return userWithoutPasswordHash
    }
    
    type Subset<T, U> = {
      [Key in keyof T]: Key extends keyof U ? T[Key] : never
    }
    But no matter what I do TypeScript complains that
    user
    does not have a
    passwordHash
    property. I found https://github.com/prisma/prisma/issues/3372, which seems like it might be related, but I didn't see anything in there about how to handle the case of merging a select object provided by arguments with some additional fields (i.e.
    { ...select, passwordHash: true }
    ). Any ideas?
  • f

    face boy

    01/22/2022, 9:12 PM
    prisma giving me errors with the release phase thing on heroku
  • f

    face boy

    01/22/2022, 9:15 PM
    Copy code
    Datasource "db": PostgreSQL database "sampletext", schema "public" at "loremipsum thisisntactuallythetextfromtheerror",
    No migration found in prisma/migrations
    Error: P3005
    The database schema for `some string of database characters` is not empty. Read more about how to baseline an existing production database: <https://pris.ly/d/migrate-baseline>
    k
    • 2
    • 1
  • f

    face boy

    01/22/2022, 9:16 PM
    how do I just delete existing tables in a database and what does the first part of that error mean
    k
    • 2
    • 1
  • r

    Rich Starkie

    01/22/2022, 9:20 PM
    Hi Everyone, new to Prisma I'm using Prisma with React (latest version) and JS, I've followed the adding Prisma to an existing project guide, and I have achieved a connection (Prisma Pulled the DB Design Schema down automagically), and can add data to the database using Studio. But ... When I come to using my App to access the data, all I get is a plain white screen, Inspecting the page however, tells me that Prisma can't be run in the browser. I'm sure its something that I have done wrong, but can anyone please advise me how I can get things going?
    t
    k
    • 3
    • 11
1...535536537...637Latest