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

    Marius Popa

    09/22/2022, 10:01 AM
    Hello everyone 🙂 just landed on my first project using Prisma with NextJs, in which I had to add a new field to a table. After the changes, I ran
    npx prisma migrate dev
    which created the latest version of the db. Locally I could see the new field in the migration, commited and pushed to github and created a PR for the change. When my colleague checked my PR, everything was alright and it was merged. However, our Dev branch is connected to the test server and the db migration seemed to fail for it, the field is not there. I would appreciate a lot if someone has some time to look over the error I drop in the comments of this thread, maybe you encounter the problem too : ) thank you a lot!
    ✅ 1
    j
    v
    • 3
    • 11
  • f

    Fishie

    09/22/2022, 11:15 AM
    Is there another community that is more active?
    🤔 1
    v
    • 2
    • 1
  • p

    Paul

    09/22/2022, 1:20 PM
    hey all, using postgres and trying to get my head around: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-scalar-lists-arrays Let’s say I have an array, that’s supposed to be a hierarchical structure, mapping to a directory list. When I traverse down the directory list. I can use the following:
    where = { path: folderId !== null ? { has: folderId } : undefined }
    But when I am at the root, I get all the files and folders. When I query in psql:
    select id, name, path from dam_file where path is null;
    Then I only get the data that’s at the root level of the directory. How do I ensure I am duplicating the psql for a Prisma query? Thanks
    ✅ 1
    n
    • 2
    • 3
  • k

    Kenny Tran

    09/22/2022, 3:32 PM
    Hey, how should I go about storing historical values? I want to store points that a user has achieved over the course of a month. Would I need to set up a points table where I store the given date and points and reference that to the user's table or how should I go about doing this? Also how would I fetch the points over the course of the last 5 days?
    👀 1
    ✅ 1
    c
    n
    • 3
    • 11
  • z

    Zac Wellmer

    09/22/2022, 4:25 PM
    is there any reason to not delete a record from the
    _prisma_migrations
    table that has an
    applied_steps_count=0
    ? I made a stupid mistake which is causing a rolled back migration to have have the same migration name as an applied migration (but different check sums)
    👀 1
    n
    • 2
    • 1
  • i

    Ivan Jeremic

    09/22/2022, 4:33 PM
    Hello I want to use MongoDB for my Project, does it make any sense to pick Prisma here over the native node.js driver?
    ✅ 1
    n
    j
    • 3
    • 2
  • e

    Eric Simon

    09/22/2022, 5:38 PM
    Is there a decorator that I can use to change the table name for a model? Also is there a decorator to change a column name of a model? for example I have the following:
    Copy code
    model User {
      user_id string
    }
    I want the table to be:
    Copy code
    create table as Users (
      userId" VARCHAR(255) NOT NULL
    )
    ✅ 1
    d
    j
    • 3
    • 2
  • n

    Nicolas Rodriguez

    09/22/2022, 5:43 PM
    Hi all, I have a quick question that I want to make sure works with Prisma before I execute it. I have a few massive tables (~20GB) with new columns that I added recently that I need to backfill. After doing some research, the fastest strategy I saw was to essentially create a clone of that table, insert all the rows into the cloned table with the right data in the column, drop the old table, then rename the cloned table to the same name as the original. Will this cause any issues with Prisma? Or will it just work? All of the same indexes/foreign key constraints will exist on the cloned table as before
    ✅ 1
    d
    j
    • 3
    • 3
  • j

    Jeremy Hinegardner

    09/22/2022, 6:33 PM
    Check the name/params of your unique constraint in the model - its probably just a snake/camelcase situation on the clause - see - https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#get-the-user-record-with-firstname-of-alice-and-lastname-of-smith-id as a reference
    a
    a
    v
    • 4
    • 7
  • ł

    Łukasz Usarz

    09/22/2022, 6:53 PM
    Hi all, I'm using
    $transaction
    API and wonder how should I write
    jest
    unit tests that checks if transaction was rollbacked when error occurred:
    Copy code
    await this.prisma.$transaction(async (prisma) => {
      const user = await prisma.user.create({ data });
      await this.mailerService.sendEmail(user);
    });
    
    //...
    jest
      .spyOn(mailerService, 'sendEmail')
      .mockImplementation(async (user: User) => {
        throw new Error('Email sent error');
      });
    👀 1
    ✅ 1
    j
    • 2
    • 1
  • k

    Kenny Tran

    09/22/2022, 8:45 PM
    Hey again, how would you guys handle fetching large amount of data? Let's say I want to fetch 100K users from my database and export their data. What's the best way to do it?
    👀 1
    ✅ 1
    k
    j
    n
    • 4
    • 5
  • s

    Sabin Adams

    09/22/2022, 11:30 PM
    prisma rainbow Hey there Prisma people! 👋🏻 I will soon be diving deep into the world of testing applications that use Prisma and want to hear from you! Do you have any specific questions, confusions, or insights into testing applications and APIs that use Prisma? Please ask away or share in the thread below! 🧵 I would love to cover as many testing topics & questions you have as possible!
    prisma rainbow 1
    j
    • 2
    • 2
  • h

    Han Han

    09/23/2022, 1:06 AM
    Hi, I have a problem with
    dbgenerated
    Postgresql look like that:
    Copy code
    CREATE OR REPLACE FUNCTION create_payment_id_code(INTEGER) RETURNS text AS $$
    SELECT CASE
        WHEN $1 < 10000 THEN 'PM' || to_char($1, 'FM00000')
        ELSE concat('TT', $1)
      END;
    $$ LANGUAGE sql immutable;
    
    ALTER TABLE public.payments
    ADD COLUMN "paymentIdCode" TEXT UNIQUE NOT NULL GENERATED ALWAYS AS (create_payment_id_code("paymentId")) STORED;
    When I use
    prisma db pull
    Copy code
    paymentIdCode              String?                    @unique @default(dbgenerated("create_payment_id_code(\"paymentId\")"))
    when run migrate then get the error:
    ERROR: cannot use column reference in DEFAULT expression.
    ✅ 1
    n
    v
    • 3
    • 2
  • d

    David Van Isacker

    09/23/2022, 1:48 AM
    Hi all, i'm using Postgres + TimescaleDB and having trouble getting the time_bucket function to work with $queryRaw. Here is the query that is failing for me:
    Copy code
    const data = await this.prisma.$queryRaw(
            Prisma.sql`SELECT time_bucket('1 day'::interval, p.time::timestamptz) from prices p limit 10`,
    );
    I get the following error:
    Copy code
    Exception occured : Error in processing the request : \nInvalid `prisma.$queryRaw()` invocation:\n\n\nRaw query failed. Code: `42883`. Message: `db error: ERROR: function time_bucket(interval, timestamp with time zone) does not exist\nHINT: No function matches the given name and argument types. You might need to add explicit type casts.`"}
    The same query works perfectly in my SQL editor. I've tried with and without type casts but i doesn't seem to work. Any ideas ? Thanks!
    ✅ 1
    n
    • 2
    • 3
  • h

    Harris Rothaermel

    09/23/2022, 3:17 AM
    My prisma schema has gotten complex over the past few days as I try to make it more open to extending in the future. I’m using “meta tables” that act as essentially a base class. So for example there is the Bot model, but then the bot can contain a reference to a DiscordBot model, SlackBot model (for example), or other future bots. The conversations these chatbots engage in then reference the base “bot” model so it can maintain 1 structure for many different platforms. Does this kind of schema make sense? I’ve attached the whole schema with comments in this thread and would love y’alls thoughts
    ✅ 1
    j
    • 2
    • 24
  • p

    Peter

    09/23/2022, 1:42 PM
    I'm trying to use Prisma to create a query similar to:
    Copy code
    SELECT * FROM user WHERE name ~* '\mhello';
    Unforunately, something like this:
    Copy code
    prisma.user.findMany({ where: { name: { contains: `\\mhello`, mode: 'insensitive' } } })
    does not work
    ✅ 1
    j
    n
    v
    • 4
    • 9
  • b

    Barnaby

    09/23/2022, 3:37 PM
    I think I've found a bug in prisma migrate, it's claiming it cannot delete a constraint because it doesn't exist but it does exist
    ✅ 1
    n
    • 2
    • 1
  • b

    Barnaby

    09/23/2022, 3:38 PM
    it's even created as part of an earlier migration, but
    prisma migrate reset
    fails
    ✅ 1
    n
    v
    • 3
    • 4
  • j

    Joey

    09/23/2022, 5:10 PM
    super easy one, cant seem to find it though, but i know prisma does it. How do i query by something that should be one of a set of values? hypothetical example of finding something with a size of 1,2,3,4 or 5
    const res = await prisma.table.findFirst({where: { size: { IN: [1,2,3,4,5] }});
    ✅ 1
  • j

    Joey

    09/23/2022, 5:12 PM
    found it, its lower case
    in
    🤦‍♂️
    🚀 1
  • v

    ven v

    09/23/2022, 5:51 PM
    hi quick question - i have a project connected to supabase db using prisma. Can i create another project and connect to the same database with a different schema? will it the new schema overwrite the existing tables? if so is there a way to avoid this?
    ✅ 1
  • v

    ven v

    09/23/2022, 5:53 PM
    do i need to do a schema pull or something?
    ✅ 1
    j
    • 2
    • 4
  • s

    saqib Bhatti

    09/23/2022, 8:03 PM
    👋 Hello, team!
    👋 4
    n
    • 2
    • 1
  • l

    Lewis

    09/24/2022, 1:55 AM
    Is there some kind of standard, or does someone have a solution to adding multiple sets of fields from an object to the database that doesn't involve spamming the database with requests for each piece of data? v e.g. the "items" array is the type of data I want to pass to the "inventory", what's the best way to pass that to the "inventory.update" function without multiple requests?
    Copy code
    const items = [{item: "thing1", amount: 1}, {item: "thing2", amount: 2}, {item: "thing3", amount: 10}];
    await prisma.inventory.update({
        where: {
            id,
        },
        data: {
            ITEM: {
                increment: AMOUNT,
            }
        }
    });
    👀 1
    n
    v
    • 3
    • 2
  • k

    Kenny Tran

    09/24/2022, 8:37 AM
    Hey, I'm using uuid as PK for my users table and I would like to use cursor based pagination. Is that possible with uuid or do I need to add another unique column that's incremental?
    ✅ 1
    j
    • 2
    • 4
  • k

    Kenny Tran

    09/24/2022, 9:48 AM
    Another question that I have is if it's safe to expose a user's uuid? A scenario would be if I wanted to visit a user's profile. The url could be something.com/12312-3oidhasid-139uUAHD
    ✅ 1
    a
    • 2
    • 2
  • m

    MrDrummer25

    09/24/2022, 9:05 PM
    Hey folks, I have a Prisma schema that uses many-to-many and one-to-many relationships. The base class for the table doesn't show these types, so my question is, is there a model that also contains the relationship data too? If so, where would I find it? Context: I'm using nest.js
    ✅ 1
    v
    • 2
    • 1
  • c

    Canaan Linder

    09/24/2022, 11:12 PM
    Hi! 🙂 Question about using a proxy with prisma (since RDS proxy doesnt work with prepared statements). Is there any way to deploy a prisma proxy on our VPC on AWS?
    ✅ 1
    n
    • 2
    • 5
  • j

    Jake W

    09/25/2022, 12:27 AM
    hey, everyone. i'm trying to work out how to use many to many relationships with prisma / mongodb and ran into a small issue. here is my schema:
    model Guild {
    id      String   @id @default(auto()) @map("_id") @db.ObjectId
    guildId String   @unique
    modules Modules
    users   Member[]
    }
    model Member {
    id       String   @id @default(auto()) @map("_id") @db.ObjectId
    rblxId   Int      @default(0)
    xp       Int      @default(0)
    userId   String   @default("0")
    medalIDs String[] @db.ObjectId
    medals   Medal[]  @relation(fields: [medalIDs], references: [id])
    guildId  String
    Guild    Guild    @relation(fields: [guildId], references: [id])
    }
    ✅ 1
    n
    • 2
    • 4
  • h

    Hasan

    09/25/2022, 8:33 AM
    is there a findoneorcreate function in the js lib ?
    ✅ 1
    m
    n
    • 3
    • 2
1...624625626...637Latest