Skip to content

Commit

Permalink
fix(usability): throw a helpful error when user attempts to define up…
Browse files Browse the repository at this point in the history
…datable unique keys
  • Loading branch information
uladkasach committed Dec 8, 2022
1 parent 5a822f3 commit ba3ff58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/logic/compose/generateSchema/generateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const generateSchema = async ({ configPath, targetDirPath }: { configPath
);
const taskSuite = new Listr(tasks);
await taskSuite.run().catch((err) => {
// console.error(err); // tslint:disable-line no-console ; // TODO: choose full error when debugging
console.error(err.message); // tslint:disable-line no-console
});
};
8 changes: 7 additions & 1 deletion src/logic/generate/entityTables/generateEntityTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ export const generateEntityTables = ({ entity }: { entity: Entity }) => {
});

// 2. validate the props
// TODO: throw error if the unique constraint has dynamic properties
const updatableUniqueKeys = Object.keys(updatableProps).filter((key) => entity.unique.includes(key));
if (updatableUniqueKeys.length)
throw new Error(
`Detected a unique key on '${
entity.name
}' which references an updatable property. This is not supported. Keys ${JSON.stringify(updatableUniqueKeys)}`,
);

// 3. define the sql
const entityTable = generateTableForStaticProperties({
Expand Down

0 comments on commit ba3ff58

Please sign in to comment.