Closed TheDoctor0 closed 2 years ago
Gave this a run in my project today which is using postgres, worked perfectly 💯
@jasonmccreary, can u review and potentially merge this PR?
I'd like to see more verify it. I don't use enums or Postgres. So I'm worried about merging it and breaking something else...
I completely understand the concerns. I'll try to make some time in coming days and test this for various field types (with and without enums) on Postgres, MySQL and SQLite to ensure that everything is working as it should.
Finally I had some time to check this. Two additional changes were made:
I created the test repository, it contains:
@jasonmccreary, as you can see, everything is working as intended.
Fix proposed in #51 for issue #50 will remove SQL error, but also make enum fields always a
$faker->word
in generated factories. PostgreSQL implementation of enum does not store allowed values in type definition, instead there is a field constraint.I came up with solution that supports both MySQL and PostgreSQL. Right now it should work even without a custom enum type for Doctrine.
I tested it with PostgreSQL and this migration:
Generated factory:
Changes that were made:
enumValues
function to check connection driver name.enumValues
is not static anymore (I honestly don't know why it was).setProperty
is returned instantly if matches any of$fakeableNames
, so it won't make a DB call for enum.$faker->randomElement
if any enum values are present (only if it's an actual enum field in database).