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

    Mateusz Stepaniuk

    07/08/2022, 7:24 PM
    welp it’s natral that it’ll take more and more time, you could try to optimise a few operations but in principle there’s not much you can do
  • m

    Mateusz Stepaniuk

    07/08/2022, 7:25 PM
    Obviously archiving isn’t a thing as you would drop some precious informations about how your schema evolved
  • m

    Mateusz Stepaniuk

    07/08/2022, 7:25 PM
    But maybe this will be a little helpful @Tom O'Neill https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/squashing-migrations
  • t

    Tom O'Neill

    07/08/2022, 7:28 PM
    Thank you @Mateusz Stepaniuk! Squashing looks like it'll be perfect 👍
    🦜 2
  • s

    Schalk Neethling

    07/08/2022, 8:12 PM
    Hey folks, if you could recommend a course to learn using Prisma with MongoDB and Nodejs, which would you recommend?
  • m

    Mateusz Stepaniuk

    07/08/2022, 8:14 PM
    Docs @Schalk Neethling, they’re amazing
    💚 1
  • s

    Schalk Neethling

    07/08/2022, 8:15 PM
    @Mateusz Stepaniuk could you recommend a starting point? I completed this bit: https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/mongodb-typescript-mongodb
    ✅ 1
    n
    • 2
    • 2
  • s

    Schalk Neethling

    07/08/2022, 8:18 PM
    I want to make sure I follow best practice etc. Like, should you have all your functions in a single file or is it better to split based on collection for example. If you split by collection, is it ok to create a new Prisma client in each? i.e.
    const prisma = new PrismaClient()
    or should you instead have a util that returns the client if one does not already exist. I have many more questions like that 🙂
    ✅ 1
    c
    • 2
    • 3
  • a

    Anthony Ma

    07/08/2022, 8:52 PM
    Hi, I'm evaluating Prisma for work and I have a few questions. I'm switching from Objection JS. The biggest hurdle I see so far is that I can't define a custom relation within the client. Here's an example. Let's say I have these tables:
    Copy code
    CREATE TABLE `iot_device` (
      `id` varchar(255) NOT NULL PRIMARY KEY,
      `type` varchar(255) NOT NULL,
      `location` varchar(255) DEFAULT NULL
    );
    
    CREATE TABLE `iot_device_status` (
      `id` int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
      `device` varchar(255) NOT NULL,
      `lost` tinyint(1) DEFAULT 0,
      `created_at` datetime(6) DEFAULT current_timestamp(6)
    );
    Since
    iot_device_status
    stores current and historic statuses from every
    iot_device
    , I use this SQL script to retrieve the current status from every unique device:
    Copy code
    SELECT * 
    FROM iot_device_status s 
    JOIN (SELECT device, MAX(created_at) AS max_date FROM iot_device_status GROUP BY device) sm
    ON s.created_at = sm.max_date
    AND s.device = sm.device;
    In Objection JS, I can define this relationship in my entity and then referenced when needed:
    Copy code
    export default class IOTDevice extends BaseEntity {
        ...
    
        static relationMappings = () => ({
            statusRelationship: {
                relation: Model.HasOneRelation,
                modelClass: IOTDeviceStatus,
                join: {
                    from: "iot_device.id",
                    to: "iot_device_status.device",
                },
                modify: function (builder) {
                    builder
                        .alias("s")
                        .join(
                            IOTDeviceStatus.raw(
                                "(SELECT device, MAX(created_at) AS max_date FROM iot_device_status GROUP BY device) AS sm"
                            ),
                            function () {
                                this.on("s.created_at", "=", "sm.max_date").andOn(
                                    "s.device",
                                    "=",
                                    "sm.device"
                                );
                            }
                        );
                },
            },
        });
    }
    
    const res = await IOTDevice.query().withGraphJoined("statusRelationship"); // returns the most recent status of each device
    but as far as I can tell, there's no support for this kind of modification to relation. I would have to implement this outside of the client. Am I just overlooking something or am I correct in that prisma has no support for something like this?
    ✅ 1
    a
    • 2
    • 2
  • z

    Zach

    07/08/2022, 9:21 PM
    is there any way to use SQL Server 2014 with Prisma even though only 2017 and 2019 are technically supported? 😬
    ✅ 1
    n
    • 2
    • 2
  • h

    Halvor

    07/08/2022, 9:34 PM
    When using BigInt in prisma.schema it expects the typescript type "bigint" not "BigInt", bigint can only hold 2^53 but i am storingnumbers of magnitude 2^63
    👀 1
    a
    v
    • 3
    • 4
  • h

    Halvor

    07/08/2022, 9:34 PM
    How to workaround this?
  • n

    Norbert Takács

    07/09/2022, 12:01 AM
    I am having some problems with a production database, all the migrations have been applied but suddenly its giving an error about a failed migration, but it shows no logs. How do I debug this ?
    Copy code
    /app # npx prisma migrate deploy
    Prisma schema loaded from prisma/schema.prisma
    Datasource "db": SQLite database "rss_bot_database.db" at "file:./../config/rss_bot_database.db"
    
    3 migrations found in prisma/migrations
    
    Error: P3009
    
    migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
    The `init` migration started at 2022-06-09 13:06:17.104 UTC failed with the following logs:
    
    
    /app #
    When I try to use
    npx prisma migrate apply --applied "migration_name"
    it says all the migrations are applied
    👀 1
    a
    • 2
    • 10
  • r

    Ryan Thomas

    07/09/2022, 3:29 AM
    If I am using Nodejs with Express, would it be best if I just created one instance of prisma?
    n
    • 2
    • 1
  • h

    humblecoder

    07/09/2022, 4:15 AM
    Can
    Prisma
    JSON filter with array values? I’m trying:
    Copy code
    findMany({
            where: {
              my_json_field: {
                path: ['my','path'],
                in: ['park','car','house'],
              },
            },
    . . . but I’m receiving a TS error
    Type '{ path: string[]; in: any[]; }' is not assignable to type 'JsonNullableFilter'.
    However, changing types doesn’t seem to matter. The path contains a single text value. It is not an array. But I still want to see if the value is “IN” the provided array. I can do this with a raw query, but I’d rather have Prisma handle it in this case for further operations. Is array filtering even possible with JSON values?
    ✅ 1
    a
    • 2
    • 3
  • a

    Annu Singh

    07/09/2022, 6:29 AM
    Is anyone familiar with this error: Property 'dateTime' does not exist on type 'ObjectDefinitionBlock<"Link"> I guess it's a Nexus & Typescript issue. Any suggestions will be helpful.
    👀 1
    ✅ 1
    • 1
    • 1
  • p

    Patrick

    07/09/2022, 12:11 PM
    I’d like to delete two items in the transaction and update one if exists. If any of those three do not exists, that’s okay. Right now it throws error when any of those do not exists. Is there better way to do this?
    Copy code
    const [configDelete, billingDelete, userUpdate] = await prisma.$transaction([
        prisma.config.delete({
          where: { uid }
        }),
        prisma.billing.delete({
          where: { uid }
        }),
        prisma.user.update({
          where: { id: uid },
          data: {
            trialDays: 0
          }
        })
      ])
    ✅ 1
    n
    • 2
    • 2
  • h

    Halvor

    07/09/2022, 12:24 PM
    With $queryRawUnsafe() i was able to do 2 queries (fist CTE and the query from that), how can i do this with $queryRaw?
    👀 1
    n
    v
    • 3
    • 2
  • a

    Aurora

    07/09/2022, 3:53 PM
    Hi everyone, I used to use
    prisma db push
    to update my database, but this time I need to use
    prisma db migrate
    . However, the CLI told me I nee to reset my database with data lost. How can I handle it? Thank you.
    ✅ 1
    n
    • 2
    • 1
  • t

    Taofiq

    07/09/2022, 9:51 PM
    Hi Guys How do i create an array for a field with prisma schema model?
    ✅ 1
    m
    • 2
    • 5
  • t

    Taofiq

    07/09/2022, 9:52 PM
    price           _String[]_   @db.VarChar(255)
    v
    • 2
    • 4
  • a

    Andrei

    07/10/2022, 8:46 AM
    Hello, is there any workaround to use a Tag model in rails way, when a tag has a taggable_id and taggable_type and it linked to multiple models?
    Copy code
    model Tag {
      id            Int       @id @default(autoincrement())
      title         String    @db.VarChar
      taggable_id   Int
      taggable_type String    @db.VarChar
      user_id       Int
    }
    👀 1
    n
    v
    • 3
    • 2
  • d

    Dog

    07/10/2022, 2:35 PM
    Hi guys 👋 I'm having some trouble creating an invites model. The idea is a user can have many invites, and each invite can invite 1 person only. So every user would have an inviter field (for the person who invited them) and a "invites" field with all the invites they have.
    ✅ 1
    m
    n
    • 3
    • 7
  • d

    Dunsin

    07/10/2022, 10:22 PM
    Hello everyone, is there a query in prisma to automatically delete a field in the database after a particular time
    ✅ 1
    n
    • 2
    • 2
  • b

    Boo

    07/10/2022, 10:26 PM
    Anybody done generated columns with prisma/mysql? Whats the proper way to do it? I run the migrate dev as
    --create-only
    and adjust the column as generated always, and then run
    migrate dev
    again
    👀 1
    n
    v
    • 3
    • 2
  • b

    Boo

    07/10/2022, 10:27 PM
    It doesn't work
  • c

    Christophe Rudyj

    07/11/2022, 12:32 PM
    Hi I have a hard tim understanding the "in" part of Prisma as i'm trying to get items from an array
    Copy code
    ['Kala','Modern Horizon']
    👀 1
    v
    n
    • 3
    • 12
  • c

    Christophe Rudyj

    07/11/2022, 12:35 PM
    if i try to run this filter it fails
    m
    v
    • 3
    • 3
  • m

    Michael Jay

    07/11/2022, 2:16 PM
    Can someone please help me understand how to add or remove records on a join table that is implicitly defined? Consider two models, Roles and Permissions, which are M:N I thought it would be like this:
    Copy code
    this.prisma.role.update({
                            where: { id: incomingRole.id },
                            data: {
                                name: incomingRole.name,
                                permissions: {
                                    deleteMany: {
                                        id: { in: permissionsToDelete.map(permission => permission.id) }
                                    },
                                    create: permissionsToCreate.map(permissionName => {
                                        return {
                                            name: permissionName
                                        }
                                    })
                                }
                            }
                        })
    But now I'm thinking that would instead delete and create actually Permission records, instead of deleting rolePermission records. Update: I decided to just explicitly define the join. I really love the implicit join syntax, but reading through the Prisma docs, it seems like to use them in queries, I have to explicitly define them.
    ✅ 1
  • m

    MrDell

    07/11/2022, 4:09 PM
    Hi, I am kind of new to Prisma so bear with me. I am currently facing issue with model whenever i am trying to create a record of it in Postgres. Here's the schema which is causing error
    Copy code
    model Player {
      id            BigInt      @id
      createdAt    DateTime?   @default(now())
      region       String
      country      String
      timezone     String
      Tournaments Tournament[]
    }
    and here i am trying to create the record in database.
    Copy code
    await prisma.player.create({
                        data: {
                            id: Number(interaction.user.id),
                            region: region,
                            timezone: REGION[region][country]["timezone"],
                            country: country,
                            
                        }),
    Here's the error which is showed in terminal.
    Copy code
    Error: 
    Invalid `prisma.player.create()` invocation:
    
    
      Unique constraint failed on the fields: (`id`)
    Can anyone tell me what's going wrong here? Any help would be appreciated!
1...595596597...637Latest