#25388 closed New feature (fixed)
Allow disabling of all migrations during tests
Reported by: | Markus Holtermann | Owned by: | |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | berker.peksag@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As an extension to #24919 a setting DATABASE['TEST']['MIGRATE'] = False
should disable all migrations on that particular database. This can be done by hooking into django.db.migrations.loader.MigrationLoader.migrations_module()
and returning None
.
Change History (23)
comment:1 Changed 8 years ago by
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Owner: | changed from nobody to Wiktor |
Status: | new → assigned |
comment:2 Changed 7 years ago by
Cc: | berker.peksag@… added |
---|---|
Patch needs improvement: | set |
comment:3 Changed 7 years ago by
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
Updated PR: https://github.com/django/django/pull/6323
comment:6 Changed 7 years ago by
Has patch: | unset |
---|---|
Resolution: | fixed |
Severity: | Normal → Release blocker |
Status: | closed → new |
Version: | master → 1.10 |
As described in #26838, this feature doesn't seem to work as migrations are disabled in more than just tests when setting DATABASES['default']['TEST'] = {'MIGRATE': False}
. If this requires more than a trivial fix, let's remove the feature from 1.10.
comment:9 Changed 7 years ago by
Resolution: | fixed |
---|---|
Severity: | Release blocker → Normal |
Status: | closed → new |
Version: | 1.10 → master |
comment:10 Changed 7 years ago by
Here's a WIP concept: https://github.com/django/django/compare/master...berkerpeksag:25388-migrate-false-v2 Added an attribute to BaseDatabaseWrapper
to be used during the creation of the test database. It's probably not the best way to solve the problem, but it prevents the bug described in #26838.
comment:11 Changed 7 years ago by
Owner: | changed from Wiktor to Eyad Toma |
---|---|
Status: | new → assigned |
Assigned to myself due to inactivity for 2 months.
Working on top of Berker's solution.
comment:12 Changed 7 years ago by
Has patch: | set |
---|
Patch submitted https://github.com/django/django/pull/7499
it wasn't possible to write tests because setting "_run_in_test_case" on the connection only works before creating the test DB.
I tried override setting and creating "ConnectionHandler" but failed because of the reason above.
comment:13 Changed 7 years ago by
Owner: | changed from Eyad Toma to Tobias McNulty |
---|
Reviewing at DUTH sprint
comment:14 Changed 7 years ago by
Needs documentation: | set |
---|---|
Needs tests: | set |
Owner: | Tobias McNulty deleted |
Patch needs improvement: | set |
Status: | assigned → new |
comment:15 follow-up: 17 Changed 7 years ago by
Another option (which I prefer over the current implementation, the more I think about it) would be to add a new option to the migrate
management command that would *only* run syncdb
(i.e., it would pass an argument into the MigrationLoader
telling it to do what you do now in the above PR). This seems less magical than the current implementation as it would facilitate passing the option down through the stack rather than setting it on a global variable (the db connection).
comment:16 Changed 7 years ago by
Another question: What about the currently documented method of suppressing migrations is insufficient? I.e., would simply improving that documentation be a suitable alternative to this ticket?
comment:17 Changed 7 years ago by
Replying to Tobias McNulty:
Another option (which I prefer over the current implementation, the more I think about it) would be to add a new option to the
migrate
management command that would *only* runsyncdb
I don't like that option. syncdb in it's current form will go away in some way or another in the future. migrate
doesn't run syncdb automatically anymore unless explicitly said otherwise.
comment:18 Changed 7 years ago by
Assigned to myself due to inactivity for 2 months.
Thank you for working on this, Eyad. By the way, the inactivity was mainly due to the lack of feedback. I'm not very experienced on this part of Django and I wasn't sure that my solution is a good one. So it would be great if you could get some feedback from the domain experts :)
comment:19 Changed 7 years ago by
My take on the motivation of this ticket is to ease the boilerplate of setting MIGRATIONS_MODULES['app'] = None
for all apps in a test settings file. I think it has some value if a nice solution is found.
comment:20 Changed 4 years ago by
This would be a very welcome addition to Django. In the mean time, we've been adding the following to all our projects test_settings
to speed up testing:
class NoMigrations: """Disable migrations for all apps""" def __getitem__(self, item): return None def __contains__(self, item): return True MIGRATION_MODULES = NoMigrations()
comment:21 Changed 4 years ago by
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Patch needs improvement: | unset |
I took a new approach in PR https://github.com/django/django/pull/12062
comment:22 Changed 4 years ago by
Owner: | set to Mariusz Felisiak <felisiak.mariusz@…> |
---|---|
Resolution: | → fixed |
Status: | new → closed |
In f5ebdfce:
https://github.com/django/django/pull/5601