Skip to content

Commit

Permalink
fix @@unique naming uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Oct 31, 2024
1 parent ecf09c8 commit 72d88b1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/schema/src/plugins/prisma/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export class PrismaSchemaGenerator {

private replicateForeignKey(
model: PrismaDataModel,
dataModel: DataModel,
delegateModel: DataModel,
concreteModel: DataModel,
origForeignKey: DataModelField
) {
Expand All @@ -499,15 +499,15 @@ export class PrismaSchemaGenerator {
(attr) => !('name' in attr && attr.name === '@unique')
);
const uniqueAttr = addedFkField.addAttribute('@unique');
const constraintName = this.truncate(`${concreteModel.name}_${addedFkField.name}_unique`);
const constraintName = this.truncate(`${delegateModel.name}_${addedFkField.name}_${concreteModel.name}_unique`);
uniqueAttr.args.push(new PrismaAttributeArg('map', new AttributeArgValue('String', constraintName)));

// fix its name
const addedFkFieldName = `${dataModel.name}_${origForeignKey.name}_${concreteModel.name}`;
const addedFkFieldName = `${delegateModel.name}_${origForeignKey.name}_${concreteModel.name}`;
addedFkField.name = this.truncate(`${DELEGATE_AUX_RELATION_PREFIX}_${addedFkFieldName}`);

// we also need to go through model-level `@@unique` and replicate those involving fk fields
this.replicateForeignKeyModelLevelUnique(model, dataModel, origForeignKey, addedFkField);
this.replicateForeignKeyModelLevelUnique(model, delegateModel, origForeignKey, addedFkField);

return addedFkField;
}
Expand Down

0 comments on commit 72d88b1

Please sign in to comment.