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

    Levi

    04/07/2022, 1:26 PM
    can someone help why i’m getting this error?
  • r

    Renato Carneiro

    04/07/2022, 4:42 PM
    Hello Prisma team, am I missing something? It’s applying “true” to every field still, using the latest version.
    n
    • 2
    • 2
  • a

    Arthur Cachero

    04/07/2022, 5:38 PM
    Hola! I have a .prettierrc.js in my root nextjs project folder. Would that mess with the prisma vs code extension. Can't figure out why my schema is not formatting...? I'm running
    "@prisma/client": "^3.12.0",
    Copy code
    module.exports = {
      semi: true,
      singleQuote: true,
      trailingComma: 'all',
      printWidth: 100,
      arrowParens: 'always',
      tabWidth: 4,
    };
    j
    • 2
    • 4
  • a

    Adrien Wald

    04/07/2022, 11:40 PM
    Trying to run prisma in a lambda but getting the following error:
    Error: Command failed with exit code 254: npx prisma migrate deploy
  • a

    Adrien Wald

    04/07/2022, 11:40 PM
    any idea what might be going wrong?
  • a

    Adrien Wald

    04/07/2022, 11:40 PM
    Copy code
    const response = require('cfn-response')
    const path = require('path')
    
    const schema = path.join(__dirname, '..', 'prisma', 'schema.prisma')
    
    async function applyMigration() {
      const execaCommand = (await import('execa')).execaCommand
      const subprocess = execaCommand(`npx prisma migrate deploy --schema=${schema}`)
      subprocess.stdout.pipe(process.stdout)
      subprocess.stderr.pipe(process.stderr)
      await subprocess
        .catch((e) => {
          console.error(e)
          throw new Error('Migration failed!')
        })
    }
    
    async function handler(event, context) {
      console.log('Received event: ', JSON.stringify(event, null, 2))
      if (event.RequestType === 'Delete') return
      await applyMigration()
        .then(() => response.send(event, context, response.SUCCESS, 'ok'))
        .catch((error) => response.send(event, context, response.ERROR, error.message))
    }
    
    exports.handler = handler
    j
    • 2
    • 12
  • n

    Noit

    04/08/2022, 2:09 AM
    Hi there, I followed the Next Vercel tutorial but made some modifications, and when I deploy to Vercel, the build on Vercel fails with this error:
    Copy code
    Type error: Property 'event' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.
    It points to this line:
    Copy code
    return prisma.event.findUnique({
    This works fine in my local dev. Any ideas why it won't deploy? Is Vercel maybe caching some build stuff so it can't see the new prisma model?
    j
    • 2
    • 3
  • w

    Wahyu

    04/08/2022, 6:56 AM
    does anyone know how to enable nexus prisma CRUD options? I see the tutorial for nexus-plugin-prisma but that is deprecated
    n
    • 2
    • 6
  • e

    Elitedev

    04/08/2022, 7:01 AM
    👋 Hello, team!
    👋 2
  • j

    Jannik Köster

    04/08/2022, 12:07 PM
  • j

    Jannik Köster

    04/08/2022, 12:08 PM
  • j

    Jannik Köster

    04/08/2022, 12:08 PM
    Hey guys, why does my User Model does not have my properties i made in my Model?
    t
    n
    • 3
    • 4
  • j

    Jannik Köster

    04/08/2022, 12:35 PM
    If have unit tests written with jest and typescript, i have set my env to test, but how can i tell prisma to use the test db?(because if cannot write js in a .prisma file.(Normally i would check it with process.env etc)
    n
    a
    • 3
    • 2
  • b

    BiffBish

    04/08/2022, 2:33 PM
    Can i ask for some help in here?
    t
    a
    • 3
    • 5
  • d

    David Marr

    04/08/2022, 3:34 PM
    I'm trying to build an "activity stream" page for my personal site, and was wondering what people suggest for a data model. I want to display data from various sources, such as Twitter API (my liked tweets, and my tweets), Github API (my starred repos), and maybe YouTube API (videos from a specific playlist). It would seem Mongo would be a good solution to store the data, since they would maybe be different collections (TweetsCollection, TwitterUsersCollection, etc), depending on their source. Does that seem reasonable? The end result I'm striving for is an ordered list of the various items (by date starred/liked/etc) so I can create some 'liveness' to the page. They would look different, so I'd need to consider how to render based on type.
    n
    • 2
    • 1
  • v

    Vinay Prabhu

    04/08/2022, 3:46 PM
    Hi everyone, Can someone tell me How to change the ownership in prisma?
    n
    • 2
    • 3
  • s

    SJ

    04/08/2022, 4:20 PM
    Does the Prisma JS client/ORM/data mapper use the HTTP protocol to communicate with the Prisma Data Platform? If so, is it possible to forego the Prisma JS client/ORM/data mapper and use the HTTP API directly? I can't find any documentation on it
    j
    • 2
    • 3
  • o

    Orcioly Andrade Alves

    04/08/2022, 5:02 PM
    Good afternoon people, As I did, the relationships are working as expected, however, I need to check so that the Model UserPermissionRole, only accepts registering if it already has a user, a role and a permission registered, that is, it cannot accept if it does not have: user, role and permission. Can anybody help me? Follow code below. CreateuserPermissionRoleService.ts:
    Copy code
    import { AppError } from '../shared/errors/AppError';
    import prismaClient from '../prisma';
    import { UserPermissionRole } from '@prisma/client';
    import { CreateUserPermissionRoleDTO } from '../dtos/create_user_permission_role_service/CreateUserPermissionRoleDTO';
    
    // type UserPermissionRoleRequest = {
    //   user_id: string;
    //   role_id: string;
    //   permission_id: string;
    // };
    
    class CreateUserPermissionRoleService {
      async execute({
        user_id,
        role_id,
        permission_id,
      }: CreateUserPermissionRoleDTO): Promise<UserPermissionRole> {
        const roleAlreadyExists = await prismaClient.userPermissionRole.findFirst({
          where: {
            role: {
              /**
               *
               * To implement
               *
               */
            },
          },
        });
    
        // console.log(roleAlreadyExists);
    
        if (!roleAlreadyExists) {
          throw new AppError('Role does not exists.');
        }
    
        const userPermissionRoleExists =
          await prismaClient.userPermissionRole.create({
            data: {
              user_id,
              role_id,
              permission_id,
            },
          });
    
        return userPermissionRoleExists;
      }
    }
    
    export { CreateUserPermissionRoleService };
    schema.prisma;
    Copy code
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model User {
      id         String   @id @default(uuid())
      name       String
      email      String   @unique
      password   String
      isAdmin    Boolean  @default(false)
      created_at DateTime @default(now())
      updated_at DateTime @updatedAt
    
      Client             Client[]
      userpermissionrole UserPermissionRole[]
      @@map("users")
    }
    
    model Client {
      id              String   @id @default(uuid())
      user_id         String
      name            User     @relation(fields: [user_id], references: [id])
      address         String
      city            String
      district        String
      state           String
      zipcode         String
      cnpj            String   @unique
      stateregistered String
      telephone       String
      mobile          String
      active          Boolean
      created_at      DateTime @default(now())
      updated_at      DateTime @updatedAt
    
      Order OrderClient[]
      @@map("clients")
    }
    
    model Product {
      id           String   @id @default(uuid())
      followUp     String
      fabric       String?
      name         String
      size         String
      color        String
      status       String
      code_karsten String
      price        Decimal  @default(0.00)
      isActive     Boolean
      created_at   DateTime @default(now())
      updated_at   DateTime @updatedAt
    
      Order OrderClient[]
      @@map("products")
    }
    
    model OrderClient {
      id           String   @id @default(uuid())
      name         Client   @relation(fields: [client_id], references: [id])
      client_id    String
      product      Product  @relation(fields: [product_id], references: [id])
      product_id   String
      quantity     Int
      size         String
      color        String
      status       String
      code_karsten String
      price        Decimal  @default(0.00)
      liquid       Decimal  @default(0.00)
      priceTotal   Decimal  @default(0.00)
      created_at   DateTime @default(now())
      updated_at   DateTime @updatedAt
    
      @@map("orders_clients")
    }
    
    model Role {
      id          String   @id @default(uuid())
      name        String
      description String
      created_at  DateTime @default(now())
      updated_at  DateTime @updatedAt
    
      permissions UserPermissionRole[]
      @@map("roles")
    }
    
    model Permission {
      id          String   @id @default(uuid())
      name        String
      description String
      created_at  DateTime @default(now())
      updated_at  DateTime @updatedAt
    
      roles UserPermissionRole[]
      @@map("permissions")
    }
    
    model UserPermissionRole {
      id            String     @id @default(uuid())
      user_id       String
      user          User       @relation(fields: [user_id], references: [id])
      role_id       String
      role          Role       @relation(fields: [role_id], references: [id])
      permission_id String
      permission    Permission @relation(fields: [permission_id], references: [id])
      created_at    DateTime   @default(now())
      updated_at    DateTime   @updatedAt
    
      @@map("permission_roles")
    }
    Something like this, I did just to try to show the idea of what I was thinking, but it didn't work.
    Copy code
    import { AppError } from '../shared/errors/AppError';
    import prismaClient from '../prisma';
    import { UserPermissionRole } from '@prisma/client';
    import { CreateUserPermissionRoleDTO } from '../dtos/create_user_permission_role_service/CreateUserPermissionRoleDTO';
    
    // type UserPermissionRoleRequest = {
    //   user_id: string;
    //   role_id: string;
    //   permission_id: string;
    // };
    
    class CreateUserPermissionRoleService {
      async execute({
        id,
        user_id,
        role_id,
        permission_id,
      }: CreateUserPermissionRoleDTO): Promise<UserPermissionRole> {
        const roleAlreadyExists = await prismaClient.userPermissionRole.findFirst({
          where: {
            role: {
              id,
            },
          },
        });
    
        if (roleAlreadyExists) {
          throw new AppError('Role does not exists.');
        }
    
        const userPermissionRoleExists =
          await prismaClient.userPermissionRole.create({
            data: {
              user_id,
              role_id,
              permission_id,
            },
          });
    
        return userPermissionRoleExists;
      }
    }
    
    export { CreateUserPermissionRoleService };
    I CAN SOLVE IT THIS WAY:
    Copy code
    import { AppError } from '../shared/errors/AppError';
    import prismaClient from '../prisma';
    import { UserPermissionRole } from '@prisma/client';
    import { CreateUserPermissionRoleDTO } from '../dtos/create_user_permission_role_service/CreateUserPermissionRoleDTO';
    
    class CreateUserPermissionRoleService {
      async execute({
        user_id,
        role_id,
        permission_id,
      }: CreateUserPermissionRoleDTO): Promise<UserPermissionRole> {
        try {
          const userPermissionRoleExists =
            await prismaClient.userPermissionRole.create({
              data: {
                user_id,
                role_id,
                permission_id,
              },
            });
    
          return userPermissionRoleExists;
        } catch {
          throw new AppError('User or role or permission doesnt exists!');
        }
      }
    }
    
    export { CreateUserPermissionRoleService };
    💯 2
    👏 2
  • b

    BiffBish

    04/08/2022, 10:27 PM
    Is there a way to select only some properties from a table and return all relations?
  • b

    BiffBish

    04/08/2022, 10:29 PM
    Copy code
    return await prisma.user.findFirst({
        select: {
          oculus_id: true,
          oculus_name: true,
        },
        include:{
          daily_stats:true,
        }
      })
    j
    n
    • 3
    • 2
  • d

    David Marr

    04/09/2022, 4:14 PM
    I'm hitting a snag with my goal, wondering if anyone has thoughts: I am trying to populate separate mongodb collections, from the response of an api call to twitter. My schema looks like: https://gist.github.com/marr/0b2e6a58858388df6b448f5d1d2dd879. The api response has a shape like:
    { data, includes: { media, users } }
    -- the includes object includes data that may be referenced in data. The challenge is that I'm trying to create entities in the db that reference each other but don't exist yet. For example, I want to create tweets that has a media relation, but the media needs to be created first. Media also has the related tweets as part of its model. Since the tweets aren't created yet, until the media is created this presents a problem. What would be the best approach here?
    n
    • 2
    • 4
  • v

    Ville

    04/09/2022, 6:10 PM
    hey, what is the reason that WhereUniqueInput does not support additional parameters to further limit the scope? https://github.com/prisma/prisma/issues/10376 Seems like a major limitation in the prisma api.
    l
    n
    • 3
    • 8
  • t

    Tejas H

    04/10/2022, 8:28 AM
    Hi folks, I am stuck on Prisma seed: When I run the command
    npx prisma migrate reset --force
    /
    npx prisma db seed
    , it gives me the following error. No idea what to do. Been searching for a solution. Please help.
    j
    • 2
    • 5
  • a

    Ali Salem

    04/10/2022, 12:54 PM
    Hey guys i have a question regarding using type-graphql prisma integration. I keep getting this error:
    n
    • 2
    • 1
  • a

    Ali Salem

    04/10/2022, 12:54 PM
    any thoughts how to resolve it?
  • o

    Orcioly Andrade Alves

    04/10/2022, 10:52 PM
    Good evening everyone, I'm having difficulty implementing ACL with Prisma and Express. I tried to use the casl/prisma library, but I didn't find the documentation clear. The code below is what is in the documentation, I don't know where to put it, if it's in a Middleware file or where. Could someone guide me or tell me another way to do ACL with prism and express?
    Copy code
    import { User, Post, Prisma } from '@prisma/client';
    import { AbilityClass, AbilityBuilder, subject } from '@casl/ability';
    import { PrismaAbility, Subjects } from '@casl/prisma';
    
    type AppAbility = PrismaAbility<[string, Subjects<{
      User: User,
      Post: Post
    }>]>;
    const AppAbility = PrismaAbility as AbilityClass<AppAbility>;
    const { can, cannot, build } = new AbilityBuilder(AppAbility);
    
    can('read', 'Post', { authorId: 1 });
    cannot('read', 'Post', { title: { startsWith: '[WIP]:' } });
    
    const ability = build();
    ability.can('read', 'Post');
    ability.can('read', subject('Post', { title: '...', authorId: 1 })));
    n
    • 2
    • 2
  • n

    Noit

    04/10/2022, 11:49 PM
    Anyone have cache issues when deploying to vercel? Is this normal - https://prisma.slack.com/archives/CA491RJH0/p1649384284408699?thread_ts=1649383777.709209&amp;cid=CA491RJH0 - I followed this tutorial by the Primsa team - https://vercel.com/guides/nextjs-prisma-postgres#step-5.-set-up-github-authentication-with-nextauth
    j
    • 2
    • 2
  • a

    amock666

    04/11/2022, 4:23 AM
    Hey guys queryraw doesn't work for me, data appear on prisma studio and there is no problem but when I try to run the query: const users = await prisma.$queryRaw`SELECT * FROM User`; , It only shows my postgres username. When I check my data on psql, It shows the same, tables appear but there is no data inside.
    n
    • 2
    • 2
  • a

    Alfred Noland

    04/11/2022, 7:41 AM
    Hi guys, we are buliding microservies in Node.js (TS) and using Prisma. For example we have different microservices, core (auth, settting), content(countries, regions...) and hotel. We are trying to keep the whole prisma schema in the core app. Now swhen I started on the content the Prisma client can access model types. Then we are getting this error message: "Property 'locationCountry' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation>'.ts(2339) View Problem" If anyone has experience with similar setup or know how to fix it, we would be very grateful. Also if interesting we can hire for a couple of hours. Also I have been using the command npx prisma db push, cant it have anything with the issue. Also how can I migrate without reset database?
    👀 1
    n
    • 2
    • 1
  • u

    user

    04/11/2022, 10:20 AM
    What's new in Prisma? (Q1/22) Learn about everything in the Prisma ecosystem and community from January to March 2022.
    🙌 2
1...561562563...637Latest