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

    Mischa

    08/19/2022, 9:57 PM
    is there any way to specify a connection timeout when fetching a prisma client? my aurora serverless DB might be asleep and i'd like to be able to wait a couple minutes for it to wake up
    ✅ 1
    n
    • 2
    • 2
  • s

    Sakar SR

    08/20/2022, 9:57 AM
    Hi, We are planning a multi-tenant app where each tenant will have their own database in different servers, we just want only change the database URL string and root the users to their db. Is this possible in Prisma? All the endpoints will be a lambda function.
    ✅ 1
    n
    • 2
    • 1
  • p

    per

    08/20/2022, 6:04 PM
    Hi, this might be noob-question, but maybe you people can give me some guidance: I’m fetching a list of “groups” which includes different stuff like a name, type, other stuff, and then lastly a “date” (coming from a DateTime in the schema). Now, when I’m sending this response, the date is a
    string
    and not a
    date
    . I know I can create a
    New Date()
    on the frontend but my types are messing up because it’s set to
    Date
    -type in the schema but it’s actually a string in my code. What is the correct way to handle this?
    👀 1
    n
    • 2
    • 3
  • c

    Clément Guibout

    08/20/2022, 6:13 PM
    Hello, Is there any to select everything but a field with prisma? If I want to select all fields on a table but not one, I need to set all the others to true Maybe I could just say something like exclude and tell which columns to exclude ?
    ✅ 1
    n
    • 2
    • 1
  • v

    Vadzim Veleshka

    08/20/2022, 7:28 PM
    Hello!
    👋 2
  • v

    Vadzim Veleshka

    08/20/2022, 7:28 PM
    https://github.com/prisma/prisma/issues/14915
    ✅ 1
  • t

    Tyler Clendenin

    08/21/2022, 1:40 AM
    I am trying to use transactions in a typescript service. essentially I have an optional options object argument
    Copy code
    options?: { $transaction?: Prisma.TransactionClient | null }
    and the line
    Copy code
    const prisma = options?.$transaction ?? this.prisma
    (where
    this.prisma
    is the
    PrismaClient
    injected into my object) unfortunately Typescript seems to think
    prisma
    is always the
    Prisma.TransactionClient
    so I can't say
    if (typeof prisma.$transaction !== 'undefined')
    to narrow the scope between what should be
    PrismaClient | Prisma.TransactionClient
    Is there any better way to conditionally run a service method in a transaction? secondary question. Is there a way given a
    Prisma.TransactionClient
    that I can pass in Promises similar to how I can run
    prisma.$transaction([prisma.model.action(), prisma.model.action2()])
    ? tertiary question, why does the
    Prisma.TransactionClient
    not have it's own $transaction method? At the very least it could just use the currently open transaction, at best it could optionally do a nested transaction or savepoint
    👀 1
    a
    • 2
    • 2
  • w

    William GM

    08/21/2022, 2:33 AM
    Has anyone had this error?
    Query createOneshipment_entry is required to return data, but found no record(s).
    Reference (https://github.com/prisma/prisma/issues/12783)
    ✅ 1
    r
    • 2
    • 3
  • t

    Tyler Clendenin

    08/21/2022, 2:46 AM
    With the new prisma queryRaw, if I am doing a
    where id IN (${Prisma.join(ids)})
    where the id is a uuid, I get the error
    Copy code
    Raw query failed. Code: `42883`. Message: `db error: ERROR: operator does not exist: uuid = text
    what do I need to do to cast those correctly?
    👀 1
    w
    n
    • 3
    • 3
  • w

    William GM

    08/21/2022, 5:11 AM
    Hello. could someone take a look at this? Something strange is happening with prisma and triggers. https://github.com/prisma/prisma/issues/14918
    ✅ 1
    r
    • 2
    • 1
  • r

    Radostin Romanov

    08/21/2022, 6:13 AM
    Hey, I started setting up my database and I decided I needed a table for users -
    users
    . In there, I have
    id, email, password, createdAt
    and so on. I soon realized that my users need roles as well, so, I created the
    roles
    column where I was to add an array of roles (I would have a
    roles
    table, connecting it all), but realized that MySQL doesn't(?) have support for arrays like that. I then settled on simply creating another table -
    userMeta
    , where I simply store
    id, role
    (where
    id
    is the user's id), in here, multiple rows can have the same user id, but not the same role, so, if I had an user with an id
    1
    and I had 2 roles -
    administrator, user
    , my
    usersMeta
    table would look as follows:
    Copy code
    id  role
    ---------
    1   administrator
    1   user
    In order for me to determine what roles an user has, I'd just simply run
    SELECT role from user_meta WHERE id=1
    . While this works, I just don't feel this is the right way to do things. I don't want to store roles as JSON, because then I can't query everything freely based on roles an user has or whatever else. Here are my current models:
    Copy code
    enum Roles {
      ADMIN
      MODERATOR
      USER
    }
    
    model User {
      id       Int    @id @default(autoincrement())
      username String @unique
      email    String @unique
    
      firstName String @map("first_name")
      lastName  String @map("last_name")
    
      createdAt DateTime @default(now()) @map("created_at")
    }
    
    model UserMeta {
      id   Int
      role Roles @default(USER)
    
      @@id([id, role])
    }
    
    model Role {
      id           Int          @id
    }
    The database works, it's how I want it to be represented, I just don't know how to write it the "Prisma way". For example, right now, the
    id
    in
    usersMeta
    is any string. I'd like there to be a relation where that id can ONLY be an id from the
    User
    model.
    ✅ 1
    w
    n
    • 3
    • 7
  • c

    Christophe Rudyj

    08/21/2022, 1:18 PM
    Hi i've been racking my head on this for days. First here's the schema
    Copy code
    // This is your Prisma schema file,
    // learn more about it in the docs: <https://pris.ly/d/prisma-schema>
    
    // The Models have been standardized this way to remove any confusion
    // in_ : denotes that it is in these related field ex: mtg is in_boxes
    // _id : is a field that requires the id of an other table like : user_id
    // _rel: This is prisma generated field
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    generator client {
      provider = "prisma-client-js"
    }
    
    model Games {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      short_hand String   @unique @db.VarChar(255)
      name       String   @unique @db.VarChar(255)
      in_boxes   Box[]
      in_sets    Sets[]
      vendor     String   @db.VarChar(255) @default("")
      sealed     String[] @db.VarChar(255)
    }
    
    model User {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      username   String   @unique @db.VarChar(255)
      password   String   @db.VarChar(255)
      role       Role     @default(USER)
      first_name String?  @db.VarChar(255)
      last_name  String?  @db.VarChar(255)
      stores     Store[]
    }
    
    model Store {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      name       String   @unique @db.VarChar(255)
      owner_id   Int?      
      users_list User[]
      boxes      Box[]
    }
    
    model Box {
      id                Int      @id @default(autoincrement())
      createdAt         DateTime @default(now())
      updatedAt         DateTime @updatedAt
      set               String   @db.VarChar(255)
      set_rel           Sets     @relation(fields: [set], references: [name])
      box_number        String   @db.VarChar(100)
      box_second_number String?  @db.VarChar(100)
      game_id           Int?     @default(1)
      game_rel          Games?   @relation(fields: [game_id], references: [id])
      store_id          Int?
      store_rel         Store?   @relation(fields: [store_id], references: [id])
    
    
    }
    
    model Sets {
      id        Int      @id @default(autoincrement())
      createdAt DateTime @default(now())
      updatedAt DateTime @updatedAt
      name      String   @unique @db.VarChar(255)
      code      String?  @db.VarChar(255)
      game_id   Int?     @default(1)
      game_rel  Games?   @relation(fields: [game_id], references: [id])
      edition   String?
      children  String[]
      in_boxes  Box[]
    
    
    }
    
    model Logs {
      id         Int      @id @default(autoincrement())
      createdAt  DateTime @default(now())
      updatedAt  DateTime @updatedAt
      store_id   Int
      user_id    Int      
      action     String   @db.VarChar(255)
      message    String   @db.VarChar(255)
    }
    
    enum Role {
      USER
      ADMIN
      CHRIS}
    Then here's the query i'm trying to do:
    Copy code
    const set = await context.prisma.sets.findFirst({
            where: {
              AND: [
                {
                  OR: [
                    {
                      name: {
                        contains: name,
                        mode: "insensitive",
                      },
                    },
                    {
                      code: {
                        contains: code,
                        mode: "insensitive",
                      },
                    },
                  ],
                },
                {
                  in_boxes: {
                   every :{
                    store_id: {
                      equals: context.req.session.storeId,
                    }
                   }
                  }
                }
              
              ],
              
            },
            select: {
              id: true,
              name: true,
              code: true,
              game_id: true,
              children: true,
              in_boxes: true,
            }
          });
    I'm trying to return the set that contains either the name or the code but only return those set who are in the boxes who have that storeId (an Int) The first way I've tried ids by getting all the boxes and then _`set?.in_boxes.filter((box: any) => box.store_id === context.req.session.storeId);` however I soon realised that the more Set request I will get the more slower this will go_ The other way is that i tried ataching the in_boxes to the OR statements however it never returns the right set An other way i've though is to go with my box table to find the set via name or code however i think it would be too cumbersome
    👀 1
    n
    v
    • 3
    • 2
  • t

    Thomas Morice

    08/21/2022, 4:53 PM
    Hello everyone! I’m currently facing an issue, where I’m trying to filter on a postgres field of type
    number
    . I basically want to filter from an input field, kind of like a
    contains
    but for a number.. Is that something we can do by any chance? Thanks in advance 🙂
    ✅ 1
    w
    n
    • 3
    • 5
  • j

    Jay Bell

    08/21/2022, 9:08 PM
    What is the suggested way to use read replicas with prisma? I see there are some proposed solutions with open issues.
    ✅ 1
    h
    n
    • 3
    • 3
  • p

    Peter

    08/22/2022, 12:22 AM
    Is it normal for the updatedAt column to always be updated even when no data is changed when using upsert: https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#update-or-create-a-related-record
    Copy code
    const update = await prisma.post.update({
      where: {
        id: 6,
      },
      data: {
        author: {
          upsert: {
            create: {
              email: '<mailto:bob@prisma.io|bob@prisma.io>',
              name: 'Bob the New User',
            },
            update: {
              email: '<mailto:bob@prisma.io|bob@prisma.io>',
              name: 'Bob the existing user',
            },
          },
        },
      },
    })
    ✅ 1
    n
    • 2
    • 1
  • r

    Robert Lee

    08/22/2022, 1:06 AM
    Do we represent json that is array first as
    Json[]
    type or
    Json
    and just shove in
    [{key:value}, ...]
    into it? Ideally i'd like to be able to do
    jsonField.map((item) => ...)
    in my code.
    👀 1
    • 1
    • 1
  • g

    Gustavo

    08/22/2022, 2:12 AM
    hi guys, qq. I'm running a migration inside an ECS container but i'm getting error:
    Copy code
    Can't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
    👀
    package.json
    Copy code
    dependencies: {
    "@prisma/client": "^4.1.0",
    },
    devDepe {
       "prisma": "^4.1.0"
    }
    Any ideas? 😬 thanks in advance 🙂 The error occurs when running the command:
    Copy code
    npx prisma generate --schema=./path/to/file/prisma/schema.prisma
    in logs I can see:
    Copy code
    Prisma schema loaded from ./path/to/file/prisma/schema.prisma
    Error: Can't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
    ✅ 1
    n
    • 2
    • 1
  • k

    KIM SEI HOON

    08/22/2022, 2:16 AM
    Hello, there was a problem during master deployment after changing from postgres url to prisma proxy url.
    InvalidDatasourceError: Datasource "db" references an environment variable "POSTGRE_DATABASE_URL" that is not set
    An error occurs. My env value is like this.
    <prisma://XXX.prisma-data.com/?api_key=XXX>
    Prisma Enabled Version:
    4.2.1
    Prisma.schema is as follows.
    datasource db {
    provider = "postgresql"
    url = env("POSTGRE_DATABASE_URL")
    }
    Is there a reason why this error occurs?
    👀 1
    r
    n
    • 3
    • 8
  • g

    Gustavo

    08/22/2022, 2:42 AM
    Is there a possibility that Prisma will support Planetscale's Serverless Driver as an alternative to the Prisma Data Proxy?
    ✅ 2
    r
    a
    • 3
    • 2
  • g

    Gustavo

    08/22/2022, 4:56 AM
    what user does prisma use to generate a client on linux? meaning if you have
    Copy code
    user     group      permissions   folder
    myUser   nogroup    drwx-r-xr-x    src
    myUser   nogroup    drwx-r-xr-x    node_modules/prisma
    myUser   nogroup    drwx-r-xr-x    node_modules/.prisma
    myUser   nogroup    drwx-r-xr-x    node_modules/@prisma
    the api I have is executed by the user: `myUser`on startup, and it also runs a separated script as a child process to run migrations from, but i get the error:
    Copy code
    Can't write to /application/node_modules/prisma please make sure you install "prisma" with the right permissions.
    which makes me think I should add the
    w
    permission to prisma folders?
    Copy code
    RUN chmod -R o+w /application/node_modules/.prisma /application/node_modules/@prisma /application/node_modules/prisma
    the script i'm using to run migrations looks like:
    Copy code
    const cmd1 = spawnSync('npx', ['prisma', 'generate', `--schema=${prismaSchema}`]);
        console.log('cmd1: ', cmd1.stdout.toString('utf8'), cmd1.stderr.toString('utf8'));
    
    const cmd2 = spawnSync('npx', ['prisma', 'migrate', 'deploy', `--schema=${prismaSchema}`]);
        console.log('cmd2: ', cmd2.stdout.toString('utf8'), cmd2.stderr.toString('utf8'));
    Could someone guide me here? 😅 All of these is running in a ECS container, any help is highly appreciated 🙂
    ✅ 1
    n
    • 2
    • 3
  • s

    sagar lama

    08/22/2022, 8:53 AM
    I have a Disambiguating relations between two models like this
    Copy code
    model Product {
      id          Int     @id @default(autoincrement())
      name        String?
      fees        Fee[]   @relation("fees")
      default_fee Fee?    @relation("default_fee")
    }
    
    model Fee {
      id             Int      @id @default(autoincrement())
      total          Float    @default(0)
      product_id     Int
      product        Product  @relation(name: "fees", fields: [product_id], references: [id], onDelete: Cascade)
      defaultable    Product? @relation(name: "default_fee", fields: [defaultable_id], references: [id])
      defaultable_id Int?     @unique
    }
    While fetching its works like expected. However while creating product with nested relations like this:
    Copy code
    const product = await this.prisma.product.create({
          data: {
           ...data,
            default_fee: {
              create: {
                // asks for product id
                total: 500,
              },
            },
          },
        });
    It asks me for product id. But it doesn't make sense to pass product_id as I wouldn't have the product id at that point. I know I can make it work by breaking the query down, but nested create doesnot seem to work for disambiguating relations. I'm curious wether it's issue on prisma or I'm missing something here Repo Link: https://github.com/sagarPakhrin/prisma-disambiguating-relations/blob/master/src/app.service.ts
    👀 1
    ✅ 1
    n
    b
    • 3
    • 11
  • s

    Sebastian Gug

    08/22/2022, 9:40 PM
    any advice on how to run the migrations on the prod database when it's inside a VPC in GCP? I'd really really really like to avoid connecting to the VPC from GH actions to run that, there must be a better way, but upon google searching not a lot of 'meaty answers' have popped up so thought I'd ask here
    g
    • 2
    • 1
  • t

    telmo

    08/23/2022, 9:02 AM
    Hey everyone- does someone knows if it's possible to directly connect to the DB from my Prisma 1 Cloud service? Looking to migrate all the data. Appreciate it
    👀 1
    ✅ 1
    a
    • 2
    • 2
  • p

    Peter

    08/23/2022, 9:38 AM
    Hey guys could use some help, been at this all night with no luck, geatly appreciate it
    Copy code
    model Domain {
      id                 String              @id @default(cuid())
      domain             String              @unique
      majesticDomainData MajesticDomainData?
    }
    
    model MajesticDomainData {
      id                     String                @id @default(cuid())
      domain                 Domain                @relation(fields: [domainId], references: [id])
      domainId               String                @unique
      topics                 MajesticTopicalData[]
    }
    
    model MajesticTopicalTrustFlow {
      id         String                @id @default(cuid())
      topic      String                @unique
      domainData MajesticTopicalData[]
    }
    
    model MajesticTopicalData {
      domainData         MajesticDomainData       @relation(fields: [domainDataId], references: [id])
      domainDataId       String
      topicalTrustFlow   MajesticTopicalTrustFlow @relation(fields: [topicalTrustFlowId], references: [id])
      topicalTrustFlowId String
      topicalPercent     Decimal                  @db.Decimal(5, 4)
    
      @@id([domainDataId, topicalTrustFlowId])
    }
    Copy code
    prisma.domain.update({
                                where: {<http://asd.com|asd.com>},
                                data: {
                                    majesticDomainData: {
                                        create: {
                                            topics: {
                                                create: [
                                                    {
                                               topic: 'health',
                                               topicalPercent: 0.24
                                                    },
                                                    {
                                              topic: 'rec',
                                             topicalPercent: 0.33
                                                    },
                                                ]
                                            },
                                        }
                                    }
                                },
                            })
    Copy code
    +             topicalTrustFlow: {
    +               create?: MajesticTopicalTrustFlowCreateWithoutDomainInput | MajesticTopicalTrustFlowUncheckedCreateWithoutDomainInput,
    +               connectOrCreate?: MajesticTopicalTrustFlowCreateOrConnectWithoutDomainInput,
    +               connect?: MajesticTopicalTrustFlowWhereUniqueInput
    +             }
    Im not sure if im connecting the many to many relationship correctly, its asking for my explicit table
    👀 2
    g
    r
    n
    • 4
    • 19
  • g

    Gustavo

    08/23/2022, 9:39 AM
    Hi guys, is there a way I can run seeds from several locations on command? In my project I have 2 packages each with its own prisma folder and everything in it, including seeds. the suggestions from the doc doesn't work for me as I need to specify 2 different path for seeds and prior I need to dynamically setup the
    DATABASE_URL
    which is working fine for migrations, but now for seeding i'm unsure how to proceed 🤔 In my script I tried running:
    Copy code
    const seeds = spawnSync('npx', ['ts-node', './src/package/package_1/prisma/seed.ts']);
    but i get the error:
    Copy code
    node:internal/modules/cjs/loader:936
      throw err;
      ^
    
    Error: Cannot find module './seed.ts'
    Require stack:
    - /application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript
        at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
        at Function.resolve (node:internal/modules/cjs/helpers:108:19)
        at requireResolveNonCached (/application/node_modules/ts-node/dist/bin.js:549:16)
        at getProjectSearchDir (/application/node_modules/ts-node/dist/bin.js:519:40)
        at phase3 (/application/node_modules/ts-node/dist/bin.js:267:27)
        at bootstrap (/application/node_modules/ts-node/dist/bin.js:47:30)
        at main (/application/node_modules/ts-node/dist/bin.js:33:12)
        at Object.<anonymous> (/application/node_modules/ts-node/dist/bin.js:579:5)
        at Module._compile (node:internal/modules/cjs/loader:1105:14)
        at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
        '/application/src/packages/package_1/prisma/imaginaryUncacheableRequireResolveScript'
      ]
    }
    Any ideas? 😄 Thanks in advance 🙂
    ✅ 1
    r
    • 2
    • 7
  • n

    Nurul

    08/23/2022, 10:08 AM
    Hey Mischa 👋 Could you please elaborate? Are you talking about
    @prisma
    folder in node_modules?
    m
    • 2
    • 6
  • m

    Michael Roberts

    08/23/2022, 10:14 AM
    Hey all, sorry if I missed the v3 to v4 migration guide, but does someone have a link for specifically dealing with this? I have quite a generic prisma app and wondering how tricky it will be to move … have we got wholescale breaking changes, or just a small amount of breaking changes? Thanks 🙂
    ✅ 1
    g
    r
    • 3
    • 2
  • f

    Fishie

    08/23/2022, 10:32 AM
    how can I use
    prisma.user.updateMany
    and disconnect a list using
    data: {discoonect: {id: 1}}
    ?
    g
    i
    • 3
    • 33
  • i

    Ignatius Hefer

    08/23/2022, 11:24 AM
    Hey there everyone: We have a development environment with a remote development postgres server (hence, everything which is merged into DEV trunc is running against remote PG development server). I've read the following: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/team-development The document mentions: "Ania and Javier make additive changes to the schema in their local environment and generate migrations" Does this then recommend a developer run a shadow DB instance (local PG db) against the remote postgress instance to obtain the latest changes from the development environment in order to test/develop against? I'm trying to understand the typical prisma development workflow using a PG Appreciate anyone's feedback here 👍
    👀 1
    n
    • 2
    • 3
  • s

    Slackbot

    08/23/2022, 11:36 AM
    This message was deleted.
1...611612613...637Latest