P
Prisma•2mo ago
LucasB25

Prisma migrate

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
6 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.
LucasB25
LucasB25OP•2mo ago
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])
}
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])
}
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])
}
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
}
model Playlist {
userId String
name String
tracks String?
lastUpdate DateTime @updatedAt //ADD
isPublic Boolean @default(false) //ADD

@@id([userId, name]) //EDITE
}
Nurul
Nurul•2mo ago
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?
LucasB25
LucasB25OP•2mo ago
hi, The request resets all database data, not just the playlist
Nurul
Nurul•2mo ago
This behaviour is going to change very soon, hopefully in next prisma version. The reset prompt will be gone.
LucasB25
LucasB25OP•2mo ago
ah nice And how should that work? because there is no utility for database schema updates?

Did you find this page helpful?