Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
[5.8] Add ability to drop types when running the migrate:fresh command #28382
PostgresSQL uses types for for enums. Currently, when using the migrate:fresh command or the RefreshDatabase trait all the tables are dropped but the types used for enums remain. This causes an error when the migrations that created those types are rerun.
This change allows dropping database types when running the migrate:fresh command. It also adds the ability to drop types when using the RefreshDatabase trait in tests.
This code change follows the same pattern that was used to allow dropping views. It adds an option to the migrate:fresh command that will drop types and allows adding a class property to have the RefreshDatabase trait drop types.
This change affects migrate:fresh rather than migrate:refresh. I believe migrate:refresh would not have a problem with Postgres types since migrate:refresh runs all the down migrations and then performs the up migrations. As long as the up migrations that created the types have corresponding down migrations that drop the types then migrate:refresh will not have any errors.
The issue is with migrate:fresh which drops all tables and then runs all the up migrations. The RefreshDatabase trait relies on migrate:fresh (I assume because it is faster).
My goal with making this change optional was to match the way views were handled. Handling views and handling types in migrate:fresh seemed like very similar problems to me so I thought the code should approach them in the same way. If you prefer that migrate:fresh always drop types if the db connection uses Postgres then I'm happy to make that change.