entc/gen: catch constraint failures in delete operations (#2664)

This commit is contained in:
Ariel Mashraki
2022-06-19 14:34:32 +03:00
committed by GitHub
parent b89b13bbdb
commit abefaa7f24
105 changed files with 545 additions and 111 deletions

View File

@@ -2342,6 +2342,28 @@ func TestIsConstraintError(t *testing.T) {
expectedFK: true,
expectedUnique: false,
},
{
name: "MySQL FK",
errMessage: "Error 1451: Cannot delete or update a parent row: a foreign key constraint " +
"fails (`test`.`groups`, CONSTRAINT `groups_group_infos_info` FOREIGN KEY (`group_info`) REFERENCES `group_infos` (`id`))",
expectedConstraint: true,
expectedFK: true,
expectedUnique: false,
},
{
name: "SQLite FK",
errMessage: `FOREIGN KEY constraint failed`,
expectedConstraint: true,
expectedFK: true,
expectedUnique: false,
},
{
name: "Postgres FK",
errMessage: `pq: update or delete on table "group_infos" violates foreign key constraint "groups_group_infos_info" on table "groups"`,
expectedConstraint: true,
expectedFK: true,
expectedUnique: false,
},
{
name: "MySQL Unique",
errMessage: `insert node to table "file_types": UNIQUE constraint failed: file_types.name ent: constraint failed: insert node to table "file_types": UNIQUE constraint failed: file_types.name`,