#Prisma migrate

10 messages · Page 1 of 1 (latest)

sharp lark
#

Hello, I have modified my Prisma schema and would like to apply the changes on my file . db without losing data, but it does not work, I lose them

lost parrotBOT
#

You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.

sharp lark
#

Old schema

generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "debian-openssl-3.0.x"]
}

datasource db {
    provider = "sqlite"
    url      = "file:./panais.db"
}

model Bot {
    botId         String     @unique @id
    totalPlaySong Int
}

model Guild {
    guildId       String      @id
    prefix        String
    language      String?     @default("EnglishUS")
    defaultVolume DefaultVolume?
    theme         Theme?
    stay          Stay?
    dj            Dj?
    premium       Premium?
    roles         Role[]
    setup         Setup?
}

model DefaultVolume {
    guildId  String  @id
    volume   Int     @default(100)
    Guild    Guild   @relation(fields: [guildId], references: [guildId])
}

model Theme {
    guildId String  @id
    theme   String  @default("classic")
    Guild   Guild   @relation(fields: [guildId], references: [guildId])
}

model Stay {
    guildId String @id
    textId  String
    voiceId String
    Guild   Guild  @relation(fields: [guildId], references: [guildId])
}

model Dj {
    guildId String  @id
    mode    Boolean
    Guild   Guild   @relation(fields: [guildId], references: [guildId])
}

model Role {
    guildId String
    roleId  String
    Guild   Guild  @relation(fields: [guildId], references: [guildId])

    @@unique([guildId, roleId])
}

model Playlist {
  userId String
  name   String
  tracks String?

  @@unique([userId, name])
}

model Setup {
    guildId   String @id
    textId    String
    messageId String
    Guild     Guild  @relation(fields: [guildId], references: [guildId])
}

model Premium {
    guildId  String  @id
    isActive Int
    Guild    Guild   @relation(fields: [guildId], references: [guildId])
}
#

New Schema

generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "debian-openssl-3.0.x"]
}

datasource db {
    provider = "sqlite"
    url      = "file:./panais.db"
}

model Bot {
    botId         String     @unique @id
    totalPlaySong Int
}

model Guild {
    guildId       String      @id
    prefix        String
    language      String?     @default("EnglishUS")
    defaultVolume DefaultVolume?
    theme         Theme?
    stay          Stay?
    dj            Dj?
    premium       Premium?
    roles         Role[]
    setup         Setup?
}

model DefaultVolume {
    guildId  String  @id
    volume   Int     @default(100)
    Guild    Guild   @relation(fields: [guildId], references: [guildId])
}

model Theme {
    guildId String  @id
    theme   String  @default("classic")
    Guild   Guild   @relation(fields: [guildId], references: [guildId])
}

model Stay {
    guildId String @id
    textId  String
    voiceId String
    Guild   Guild  @relation(fields: [guildId], references: [guildId])
}

model Dj {
    guildId String  @id
    mode    Boolean
    Guild   Guild   @relation(fields: [guildId], references: [guildId])
}

model Role {
    guildId String
    roleId  String
    Guild   Guild  @relation(fields: [guildId], references: [guildId])

    @@unique([guildId, roleId])
}

model Playlist {
    userId     String
    name       String
    tracks     String?
    lastUpdate DateTime @updatedAt
    isPublic   Boolean  @default(false)

    @@id([userId, name])
}

model Setup {
    guildId   String @id
    textId    String
    messageId String
    Guild     Guild  @relation(fields: [guildId], references: [guildId])
}

model Premium {
    guildId  String  @id
    isActive Int
    Guild    Guild   @relation(fields: [guildId], references: [guildId])
}
#

I just changed Playlist

Old

model Playlist {
  userId String
  name   String
  tracks String?

  @@unique([userId, name])
}

New

model Playlist {
    userId     String
    name       String
    tracks     String?
    lastUpdate DateTime @updatedAt //ADD
    isPublic   Boolean  @default(false) //ADD

    @@id([userId, name]) //EDITE
}
opal shadow
#

Hey 👋

If I understand correctly, you get a prompt asking you to reset the database once you have added lastUpdate and isPublic columns to your model, right?

To me it looks like you have made lastUpdate column as required but your existing records won't have the data for this column, which is why you are getting a reset prompt.

Can you make it optional, backfill the data and then make the column mandatory?

sharp lark
#

hi, The request resets all database data, not just the playlist

opal shadow
#

This behaviour is going to change very soon, hopefully in next prisma version. The reset prompt will be gone.

sharp lark
#

ah nice

sharp lark
#

And how should that work?