Rev
PPrisma
•Created by Rev on 8/1/2024 in #help-and-questions
Optimistic Locking in prisma
There is any way to define that a field in database is the locking and automatically validate?
Example:
model User {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
version Int @Version
}
and every time that i need to update the table user i need to send the version and the prisma automatically validate if version is the same else throw an exception
2 replies
PPrisma
•Created by Rev on 8/1/2024 in #help-and-questions
There are easy way to use transaction in prisma?
I have the controller, service and repository and only the repository must have the prisma client implementation, but i need to use prisma service inside the service to initialize an transaction and pass to the repository the transaction instance...
in spring boot i only need to add the @Transaction in the main service function and everthing inside is in transaction
Service:
await this.prisma.$transaction(
async (transaction: Prisma.TransactionClient) => {
const createdCompany = await this.companyRepository.createCompany(
companyCreate,
transaction,
);
})
Repository:
async createCompany(
companyBody: PrismaInterfaces.CompanyCreateInput,
transaction?: PrismaInterfaces.TransactionClient,
) {
const prisma = transaction || this.prisma;
return await prisma.company.create({
data: companyBody,
});
}
5 replies
PPrisma
•Created by Rev on 8/1/2024 in #help-and-questions
How to run SQL query after each the migration
I have an enum
enum AssignmentsEnum {
DASHBOARD_READ
REAL_TIME_READ
USER_READ
USER_CREATE
USER_UPDATE
USER_RESEND_MAIL
USER_CHANGE_STATUS
USER_BLOCK
}
And a table
model Assignment {
id Int @id @default(autoincrement())
name AssignmentsEnum @unique
description String? @db.VarChar(255)
@@map("TB_ASSIGNMENT")
@@schema("public")
}
Every time that i add new enum for AssignmentsEnum i need to run a sql to add in the Assignment table the relation:
INSERT INTO "TB_ASSIGNMENT" (name, description) VALUES ('UNATTACH_DEMAND', 'Permissão para desvincular demanda');
file: 20230321001108_assignment_enum_insert_unattach_demand
how could i do it automatized after run the migration: 20230321001108_assignment_enum_insert_unattach_demand
4 replies