Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Add ability to drop types when running the migrate:fresh command #28382

Merged
merged 2 commits into from
May 6, 2019

Conversation

drewrichards
Copy link

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.

@drewrichards drewrichards changed the title Add ability to drop types when running the migrate:fresh command [5.8] Add ability to drop types when running the migrate:fresh command May 1, 2019
@taylorotwell
Copy link
Member

Why would it be an option? Would you ever want to run migrate:refresh without dropping types?

@drewrichards
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants