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

    Jan G.

    02/08/2022, 4:41 AM
    Hi @Sophia Have you tried the solutions on this thread?
  • s

    Sophia

    02/08/2022, 5:00 AM
    Yes, I've tried both of those. I still get
    Error: Cannot find module '_http_common'
    .
  • s

    Sophia

    02/08/2022, 5:00 AM
    Thanks though.
    ❤️ 1
  • w

    Wahyu

    02/08/2022, 8:18 AM
    question, how do you create a unique index on a lower cased column in postgres? my use case is to prevent duplicate emails with different cases
    m
    • 2
    • 2
  • o

    Oleg Rudak

    02/08/2022, 10:16 AM
    Hi everyone! My question: I need both dataProxy and interactiveTransactions, how can I do it? Or is there analog to $transaction call?
    n
    • 2
    • 3
  • a

    Artem

    02/08/2022, 3:36 PM
    Hey, folks 👋 I'm having issues deploying Prisma to Vercel: my edge function bundles
    @prisma/client
    , which attempts to read the
    config2.datamodelPath
    at
    LibraryEngine
    . Sharing more details below 👇
    r
    • 2
    • 12
  • c

    Cody Moore

    02/08/2022, 3:47 PM
    Hello all. Does anyone have any experience converting SQL Server Column names from Pascalcase to Camelcase? It is an existing DB that cannot be modified. I have done some searching online and can't seem to find an efficient solution. Any help would be greatly appreciated.
    a
    • 2
    • 15
  • y

    Yaakov

    02/08/2022, 8:20 PM
    Hi, is there a way to require one of two relations? In the case below, Person must relate either to a Doctor or to a Lawyer.
    Copy code
    model Person {
      id     Int     @id @default(autoincrement())
      doctor Doctor?
      lawyer Lawyer?
    }
    
    model Doctor {
      id     Int    @id
      person Person @relation(fields: [id], references: [id])
    }
    
    model Lawyer {
      id     Int    @id
      person Person @relation(fields: [id], references: [id])
    }
    a
    • 2
    • 3
  • p

    Peter Kellner

    02/08/2022, 8:38 PM
    I just did a very simple what I thought should have been a join with SqlServer. I'm surprised to see to sql selects with full table scans. Is there some way to compel or check to see what a join did not happen? This is my prisma code:
    Copy code
    const data = await context.prisma.News.findMany({
      include: { CodeCampYear: true }
    });
    Copy code
    model News {
      Id                Int          @id(map: "PK__News__3214EC07CA2FD4E0") @default(autoincrement())
      CodeCampYearId    Int
      Visible           Boolean?
      Title             String?      @db.VarChar(256)
      Description       String       @db.VarChar(1024)
      Authors           String       @db.VarChar(256)
      CreatedDate       DateTime     @db.DateTime
      UpdatedDate       DateTime?    @db.DateTime
      ContentData       String?      @db.Text
      UrlExternal       String?      @db.VarChar(512)
      PostDate          DateTime?    @db.DateTime
      YouTubeUrl        String?      @db.VarChar(256)
      AuthorImageUrl    String?      @db.VarChar(256)
      AuthorAttendeesId Int?
      AuthorEmail       String?      @db.VarChar(128)
      YouTubeCode       String?      @db.VarChar(128)
      PictureUrl        String?      @db.VarChar(128)
      CodeCampYear      CodeCampYear @relation(fields: [CodeCampYearId], references: [Id], onUpdate: NoAction, map: "News_fk")
    
      @@unique([CodeCampYearId, Title], map: "News_uq")
    }
    Copy code
    model CodeCampYear {
      Id                         Int                       @id(map: "PK__CodeCamp__3214EC07BF12A5BA")
      Name                       String                    @db.VarChar(128)
      ...
      VolunteerJob               VolunteerJob[]
    }
    and the generated sql logged SELECT [ dbo ].[ CodeCampYear ].[ Id ], [ dbo ].[ CodeCampYear ].[ Name ], [ dbo ].[ CodeCampYear ].[ CampStartDate ], [ dbo ].[ CodeCampYear ].[ CampEndDate ], [ dbo ].[ CodeCampYear ].[ CodeCampDateString ], [ dbo ].[ CodeCampYear ].[ CodeCampSaturdayString ], [ dbo ].[ CodeCampYear ].[ CodeCampSundayString ], [ dbo ].[ CodeCampYear ].[ HostName ], [ dbo ].[ CodeCampYear ].[ BaseUrl ], [ dbo ].[ CodeCampYear ].[ UrlPostToken ], [ dbo ].[ CodeCampYear ].[ TagLine ], [ dbo ].[ CodeCampYear ].[ CodeCampYearTypeId ], [ dbo ].[ CodeCampYear ].[ EmailFooterImage ], [ dbo ].[ CodeCampYear ].[ EmailHeaderImage ], [ dbo ].[ CodeCampYear ].[ EmailBgImage ], [ dbo ].[ CodeCampYear ].[ EmailAdLinkUrl ], [ dbo ].[ CodeCampYear ].[ EmailAdLinkImage ], [ dbo ].[ CodeCampYear ].[ EmailAdLinkImageMarginTop ], [ dbo ].[ CodeCampYear ].[ EmailAdLinkImageWidth ], [ dbo ].[ CodeCampYear ].[ MeetupDetailsRequiredWord1 ], [ dbo ].[ CodeCampYear ].[ MeetupDetailsRequiredWord2 ], [ dbo ].[ CodeCampYear ].[ MeetupReferralUrl ], [ dbo ].[ CodeCampYear ].[ MeetupGroupReferralImage ], [ dbo ].[ CodeCampYear ].[ MeetupReferralText ], [ dbo ].[ CodeCampYear ].[ SiteLocked ], [ dbo ].[ CodeCampYear ].[ NgUrlDefault ], [ dbo ].[ CodeCampYear ].[ LiveStreamFeedOverride ], [ dbo ].[ CodeCampYear ].[ ShowLiveFeedStart ], [ dbo ].[ CodeCampYear ].[ ShowLiveFeedEnd ], [ dbo ].[ CodeCampYear ].[ LiveFeedEmbedCode ], [ dbo ].[ CodeCampYear ].[ LiveFeedEmbedCodeEmpty ], [ dbo ].[ CodeCampYear ].[ LiveFeedTitle ], [ dbo ].[ CodeCampYear ].[ LiveFeedTrackId ], [ dbo ].[ CodeCampYear ].[ LiveFeedSponsorNameDefault ], [ dbo ].[ CodeCampYear ].[ LiveFeedSponsorUrlDefault ], [ dbo ].[ CodeCampYear ].[ LiveFeedCurrentSessionId ], [ dbo ].[ CodeCampYear ].[ Address ], [ dbo ].[ CodeCampYear ].[ City ], [ dbo ].[ CodeCampYear ].[ State ], [ dbo ].[ CodeCampYear ].[ Zipcode ], [ dbo ].[ CodeCampYear ].[ LocationName ], [ dbo ].[ CodeCampYear ].[ HackathonDateString ], [ dbo ].[ CodeCampYear ].[ HackathonLocation ], [ dbo ].[ CodeCampYear ].[ HackathonLocationUrl ] FROM [ dbo ].[ CodeCampYear ] WHERE 1 = 1 [] Query CodeCampYear.findMany took 792ms SELECT 1 [] SELECT [ dbo ].[ News ].[ Id ], [ dbo ].[ News ].[ CodeCampYearId ], [ dbo ].[ News ].[ Visible ], [ dbo ].[ News ].[ Title ], [ dbo ].[ News ].[ Description ], [ dbo ].[ News ].[ Authors ], [ dbo ].[ News ].[ CreatedDate ], [ dbo ].[ News ].[ UpdatedDate ], [ dbo ].[ News ].[ ContentData ], [ dbo ].[ News ].[ UrlExternal ], [ dbo ].[ News ].[ PostDate ], [ dbo ].[ News ].[ YouTubeUrl ], [ dbo ].[ News ].[ AuthorImageUrl ], [ dbo ].[ News ].[ AuthorAttendeesId ], [ dbo ].[ News ].[ AuthorEmail ], [ dbo ].[ News ].[ YouTubeCode ], [ dbo ].[ News ].[ PictureUrl ] FROM [ dbo ].[ News ] WHERE 1 = 1 [] Query News.findMany took 556ms
  • e

    Elie Steinbock

    02/09/2022, 12:04 AM
    hey, wondering if anyone has suggestions for easily seeding data for testing. we’d even take a snapshot of our prod database to do this to make it quick. just a very trimmed down version of it. alternatively tools that can take a prisma schema and generate a lot of data from it automatically
  • j

    Jonathan Marbutt

    02/09/2022, 1:20 AM
    Are there any plugins for VS code that can give a clearer error for whats missing?
  • j

    Jonathan Marbutt

    02/09/2022, 1:21 AM
    I know I can dig down in the
    accountCreateInput
    but it would be awesome if there was some way to just see
    FirstName is missing
  • m

    Michael Aubry

    02/09/2022, 3:31 AM
    For some odd reason this function is creating two records, even though when I log the function it only prints once
    Copy code
    return prisma.media.create({
      data: {
        duration,
        loading,
        mediaurl,
        name,
        type,
        user: {
          connect: {
            id: ownerId,
          },
        },
      },
    });
  • g

    Gelo

    02/09/2022, 6:14 AM
    Will prisma ignore undefined property defined inside where clause?
    s
    • 2
    • 2
  • b

    Brothak

    02/09/2022, 7:55 AM
    Hi, I am starting with Prisma and I followed https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/add-prisma-migrate-to-a-project#initialize-migration-history. 1. I ran prisma db pull 2. Change name of models and added @@map 3. Run prisma migrate dev --name initial-migration --create-only I expected prisma to generate migration file without any problems. Instead I have a message saying Drift detected with list of changes: 1. Added tables 2. Bunch of Added index , unique index etc across different table. Why there is a drift if I started with clean slate , generated prisma schema using DB Pull?
    n
    • 2
    • 8
  • b

    Brothak

    02/09/2022, 7:56 AM
    Btw this is production database, but I have a data in tables which I can’t loose nor I can easily backup.
  • b

    Brothak

    02/09/2022, 8:08 AM
    Is this is a correct place to ask questions?
    ✅ 1
  • n

    Nima

    02/09/2022, 9:38 AM
    Has anyone actually got a Typescript lambda working with data proxy? the examples in the doc are using just JS and I can't quite get it to work
    a
    • 2
    • 9
  • b

    Brothak

    02/09/2022, 1:23 PM
    I have table User , which: • has relationship 1:m with posts (defined through @relation) • has relationship m:1 with UserType (defined through @relation) and I would like to write a query which would return: • name of User • count of total number of related posts • UserType.label I was able to write a query to fet name and count but not include UserType properly. I could include type_id but thats identifier and I would have to label:
    Copy code
    return this.prisma.users.findMany({
          select: {
            name: true,
            type_id: true,
            _count: {
              select: {
                posts: true
            }
          }
          }
        });
      }
    }
    n
    • 2
    • 11
  • k

    Kay Khan

    02/09/2022, 1:59 PM
    Does anyone have any experience with mocking prisma using mocked from ts-test?
  • k

    Kay Khan

    02/09/2022, 2:12 PM
    PrismaService is my `@prisma/client `singleton
    Copy code
    import { PrismaService } from "@services/mysql.service";
    import { mocked } from "ts-jest/utils";
    import faker from "@faker-js/faker";
    import { GetBrands } from "./brand";
    jest.mock("@services/mysql.service");
    
    /**
     * @group unit
     */
    
    describe("Brand", () => {
        afterAll(async () => {});
    
        it("should get a list of brands", async () => {
            const mockedData = [
                {
                    id: faker.datatype.uuid(),
                    name: faker.datatype.string(),
                    image: {
                        source: "some_source",
                        dtype: "some_dtype",
                    },
                },
            ];
            const mockedPrismaService = mocked(PrismaService, true);
            //@ts-ignore
            mockedPrismaService.brand.findMany.mockResolvedValueOnce(mockedData);
    
            const [response, error] = await GetBrands();
    
            console.log(response, error);
        });
    });
    However im getting the error, apparently
    mockedPrismaService
    is undefined
    Copy code
    TypeError: Cannot read properties of undefined (reading 'brand')
  • k

    Kay Khan

    02/09/2022, 3:13 PM
    Nevermind decided to use the appraoch here https://www.prisma.io/docs/guides/testing/unit-testing with jest-mock-extended
  • a

    Alex Vilchis

    02/09/2022, 3:19 PM
    Hi, guys. What is the difference between referential actions & referential integrity? 🤔
    n
    • 2
    • 3
  • a

    Anirudh Nimmagadda

    02/09/2022, 3:23 PM
    Hi everyone, is there a way to ignore/bypass prisma's
    The migration ... was modified after it was applied. We need to reset the database
    error in dev? I'm running
    prisma migrate dev --create-only
    . I've already done a manual check to verify that the db and migrations are in-sync. I want to avoid re-seeding my dev database - there's a lot of test data and re-seeding it in a reasonable amount of time would involve a lot of index hackery.
  • c

    Cristian Salamea

    02/09/2022, 3:34 PM
    Hi team!, I am new with prisma, so I am looking for extend model class, so I have a User model and I want to extend to implement a function
    getLastName()
    or
    getfirstName()
    so when I
    const user = await prisma.User.FindOne({})
    then can do:
    user.getLastName()
    its possible that ?
    n
    • 2
    • 4
  • u

    user

    02/09/2022, 6:00 PM
    Enabling static egress IPs in the Prisma Data Platform We're launching Early Access support for static egress IPs. Keep your databases secure by ensuring that the Prisma Data Platform only connects to your database from specific IPs. Try it out and share your feedback.
  • c

    Cody Moore

    02/09/2022, 6:50 PM
    Does this workflow seem correct to everyone? I am trying to rename the fields coming out of the DB using
    @map
    in the schema file (image attached) Once I make a change I run
    yarn prisma generate
    and the
    .prisma/client
    folder is updated in
    node_modules
    Looking at the index.js file, nothing seems to be changed and I am still getting the column name (image attached). Seems like it is ignoring
    @map
    . Am I doing something wrong. This seems so simple but yet I am banging my head against the wall. Any help would be greatly appreciated. Running the latest version of
    prisma
    and
    @prisma/client
    .
    t
    • 2
    • 12
  • m

    mel

    02/09/2022, 7:34 PM
    I’m running into an issue using references where the id is a uuid string. I have a user model with:
    Copy code
    model User {
      id        String   @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
      request   Request?
      createdAt DateTime @default(now()) @db.Timestamptz(6)
      updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(6)
    }
    
    model Request {
      id                Int @id @default(autoincrement())
      user              User   @relation(fields: [id], references: [id])
      // I also tried making the relation field userId
      createdAt         DateTime @default(now()) @db.Timestamptz(6)
      updatedAt         DateTime @default(now()) @updatedAt @db.Timestamptz(6)
    }
    When I try to migrate this, I get an error that says:
    failed to apply cleanly to the shadow database. Error: db error: ERROR: foreign key constraint “Request_userId_fkey” cannot be implemented DETAIL: Key columns “userId” and “id” are of incompatible types: text and uuid.
    The prisma documents dont show an example using uuid. The example they do give has a second parameter in the Profile model which has a userId as an Int. I tried adding this to my Request model (as an int, as a string and as a uuid). None of these worked.
    Copy code
    model User {
      id      Int      @id @default(autoincrement())
      email   String   @unique
      name    String?
      role    Role     @default(USER)
      posts   Post[]
      profile Profile?
    }
    
    model Profile {
      id     Int    @id @default(autoincrement())
      bio    String
      user   User   @relation(fields: [userId], references: [id])
      userId Int
    }
    How can I reference a userId when it is generated using uuid? thank you
    a
    • 2
    • 6
  • o

    Okan Yıldırım

    02/09/2022, 7:48 PM
    Hello, how can I convert Float to number in type generation?
  • o

    Okan Yıldırım

    02/09/2022, 7:48 PM
    Prisma generates it like Prisma.Float but I want to make it number by default
1...543544545...637Latest