Anas Badran
Anas Badran
Explore posts from servers
PPrisma
Created by Anas Badran on 8/23/2024 in #help-and-questions
Image storing
Hi everyone, I just want to know what is the best way to store images according to these info about the system I'm building. - a user needs to have a profile picture. - I need to store a number of images for each user. - a user can create a post, and the post may have an image. - The hero section of the app may have a dynamic image that the admin can change. - I need to store a number of images for each activity 'activity is a table to hold some info about an activity' created.
2 replies
PPrisma
Created by Anas Badran on 8/11/2024 in #help-and-questions
unique constraints
How to tell prisma that I want only one image with isPrimary set to true but also allow any number of images with isPrimary set to false for the same drugItem?
model Image {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
publicID String @unique
width Int
height Int
url String
isPrimary Boolean @default(false)
drugItemID String? @db.ObjectId
drugItem DrugItem? @relation(fields: [drugItemID], references: [id], onDelete: Cascade)
}
model Image {
id String @id @default(auto()) @map("_id") @db.ObjectId
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
publicID String @unique
width Int
height Int
url String
isPrimary Boolean @default(false)
drugItemID String? @db.ObjectId
drugItem DrugItem? @relation(fields: [drugItemID], references: [id], onDelete: Cascade)
}
4 replies
PPrisma
Created by Anas Badran on 6/23/2024 in #help-and-questions
One of two fields (or both) must be provided.
how to defina a constraint that one of two fields (or both) must be provided but they can't be both null
2 replies
PPrisma
Created by Anas Badran on 5/19/2024 in #help-and-questions
Unable to run the seed script successfully
The seed script
import { db } from '@/app/lib/database';
import * as data from '@/app/lib/placeholder-data';

async function main() {
for (const c of data.customers) {
await db.customer.create({ data: c });
}
for (const i of data.invoices) {
await db.invoice.create({ data: i });
}
for (const r of data.revenue) {
await db.revenue.create({ data: r });
}
for (const u of data.users) {
await db.user.create({ data: u });
}
}
main();
console.log('the database has seeded successfully');
import { db } from '@/app/lib/database';
import * as data from '@/app/lib/placeholder-data';

async function main() {
for (const c of data.customers) {
await db.customer.create({ data: c });
}
for (const i of data.invoices) {
await db.invoice.create({ data: i });
}
for (const r of data.revenue) {
await db.revenue.create({ data: r });
}
for (const u of data.users) {
await db.user.create({ data: u });
}
}
main();
console.log('the database has seeded successfully');
the package.json seed script
"seed": "ts-node prisma/seed.ts"
"seed": "ts-node prisma/seed.ts"
7 replies