-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Remove post migrate handler with a default instance creation via Migration #219
Conversation
CI fails. |
even though not the most elegant method, I chose to go with raw sql. Using I'm open to any alternate ideas for inserting data during migration without jumping through signals tho |
for more information, see https://pre-commit.ci
Codecov ReportBase: 95.70% // Head: 94.49% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #219 +/- ##
==========================================
- Coverage 95.70% 94.49% -1.21%
==========================================
Files 37 37
Lines 419 418 -1
==========================================
- Hits 401 395 -6
- Misses 18 23 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
note : Tests are currently broken on sqlite for django < 2.0 .. looks some kind of error parsing multiline SQL statements (only for sqlite)? @fabiocaccamo any idea when you might be dropping support for django < 2.2 ? (mentioned here) |
I don’t think it’s correct to modify a migration that’s already deployed. Why not add a new migration, and use apps.get_model without issue? |
The app_model can change again in the future. Then it will be inconsistent again :( .. so raw SQL is the cleanest way to keep it I added the raw SQL to the first migration as that's the least risk for inconsistency. Adding it later risks accidental data-overwriting shenanigans |
No it will not? People run migrations up to the one that creates a default Theme, then new migrations will add fields with default value, so nothing breaks. It just does not make sense to create a Theme version 0022 in the migration 0001. |
The result of the app_model returns the fields configured in code. There have been some field renaming in the past migrations. So if there are any new renames or removals in the models, that breaks the result from app_model vis-à-vis the migration state. Insert stmt will be run with columns and values not in the table as well. So just by adding the raw sql in the initial migration, i can ensure that new migration is consistent and old ones are never touched. We would not like to have new db entry added for something already in production by a third party library To clarify, the sql script inserts for version 1. The app_model tries to insert for version 28. |
I’m open to any alternative ideas that account for rename and field removal. 👍 |
Editing deployed migrations is a django no-go. I am not going to migrate my servers to 0001 then up again and lose my data. I am sorry but I do not understand your point about using apps.get_model. I use it quite often to populate data. |
Hmm.. maybe I’m mixing something up. This is the error message i see when i use app_model in the initial migration.
You can checkout the commit results here I’ll take a another look tmrw |
Added new commit with two migrations (one with app_model and second with field rename) that show why tests break if we go with the app_model approach. The issue has never been the logic itself. I'm completely on board with that. It's more about the tests, they don't even start :( |
I think that here we are really overcomplicating the problem, I will drop the
|
This functionally works when running migrations and skips the default theme creation issue on app installation.