[Django] #31318: sqlmigrate doesn't allow inspecting migrations that have been squashed

18 views
Skip to first unread message

Django

unread,
Feb 28, 2020, 8:25:23 AM2/28/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------------------+------------------------
Reporter: Adam (Chainz) Johnson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------------+------------------------
This project for another ticket can be used to reproduce:
https://github.com/adamchainz/django-unique-together-bug

When running sqlmigrate to pick up migration 0001 in this project, it
complains that two migrations have that prefix:

{{{
$ python manage.py sqlmigrate testapp 0001
CommandError: More than one migration matches '0001' in app 'testapp'.
Please be more specific.
}}}

But when trying to be more specific, it's not possible to load it:

{{{
$ python manage.py sqlmigrate testapp 0001_initial
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/.../django/django/core/management/__init__.py", line 401, in
execute_from_command_line
utility.execute()
File "/.../django/django/core/management/__init__.py", line 395, in
execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/.../django/django/core/management/base.py", line 328, in
run_from_argv
self.execute(*args, **cmd_options)
File "/.../django/django/core/management/commands/sqlmigrate.py", line
30, in execute
return super().execute(*args, **options)
File "/.../django/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/.../django/django/core/management/commands/sqlmigrate.py", line
64, in handle
plan = [(executor.loader.graph.nodes[targets[0]],
options['backwards'])]
KeyError: ('testapp', '0001_initial')
}}}

It would be nice to:

A) catch this error and report a nice message as well
B) allow inspection of individual migrations that have been involved in a
squash. Normally the workflow is to remove the individual migrations some
time after committing the squash, but until that is done it could be
useful to see their sql.

--
Ticket URL: <https://code.djangoproject.com/ticket/31318>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 1, 2020, 2:05:03 PM3/1/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* owner: nobody => David Wobrock
* status: new => assigned


Comment:

Hi! This seems quite relevant to me, as in the company I work for, we'll
probably start using squashed migration soon-ish and we use sqlmigrate
extensively.

I'd like to tackle this change :)
It does not seem too complicated to allowed inspecting the SQL of replaced
migrations.
I already wrote a small test that reproduces the behaviour described in
the stacktrace.

Technically, I guess I should be able to find an elegant way to detect the
migration was replaced and find it in the MigrationLoader.
Visually, should the command display that the inspected migration is
replaced and by which squashed migration?

Thanks!
David

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:1>

Django

unread,
Mar 1, 2020, 5:19:43 PM3/1/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by David Wobrock):

* has_patch: 0 => 1


Comment:

Patch: https://github.com/django/django/pull/12518

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:2>

Django

unread,
Mar 2, 2020, 2:15:09 AM3/2/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:3>

Django

unread,
Mar 3, 2020, 7:14:13 AM3/3/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Adam (Chainz) Johnson):

Sorry didn't see your comment until now, went through my spam box.

> Visually, should the command display that the inspected migration is
replaced and by which squashed migration?

I don't think that's necessary. The recommended procedure with a squashed
migration is to drop the originals after every developer and deployment
has received the squashed one. So the state where both exist in parallel
doesn't live for long.

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:4>

Django

unread,
Mar 6, 2020, 7:41:04 AM3/6/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:6>

Django

unread,
Mar 9, 2020, 3:50:10 AM3/9/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:7>

Django

unread,
Mar 9, 2020, 4:21:32 AM3/9/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"b88ad1d356844da10035af6e09603afdaf84a169" b88ad1d3]:
{{{
#!CommitTicketReference repository=""
revision="b88ad1d356844da10035af6e09603afdaf84a169"
Refs #31318 -- Added tests for inspecting squashed migrations and
ambiguous names in sqlmigrate.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:8>

Django

unread,
Mar 9, 2020, 4:21:33 AM3/9/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d88365708c554efe3c786c3be6da1d9de916360f" d8836570]:
{{{
#!CommitTicketReference repository=""
revision="d88365708c554efe3c786c3be6da1d9de916360f"
Fixed #31318 -- Allowed sqlmigrate to inspect squashed migrations.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:11>

Django

unread,
Mar 9, 2020, 4:21:33 AM3/9/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"71c1b7fb34109e6270841eb5d2dcd60f8a22453b" 71c1b7f]:
{{{
#!CommitTicketReference repository=""
revision="71c1b7fb34109e6270841eb5d2dcd60f8a22453b"
Refs #31318 -- Moved MigrationExecutor.collect_sql() to MigrationLoader.

collect_sql() is used only in sqlmigrate.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:9>

Django

unread,
Mar 9, 2020, 4:21:34 AM3/9/20
to django-...@googlegroups.com
#31318: sqlmigrate doesn't allow inspecting migrations that have been squashed
-------------------------------------+-------------------------------------
Reporter: Adam (Chainz) | Owner: David
Johnson | Wobrock
Type: | Status: assigned
Cleanup/optimization |
Component: Migrations | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"271e108b29a1c280f20251b035fb8ca9a202b249" 271e108b]:
{{{
#!CommitTicketReference repository=""
revision="271e108b29a1c280f20251b035fb8ca9a202b249"
Refs #31318 -- Optimized sqlmigrate by using MigrationLoader.

Only loader from MigrationExecutor was used.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31318#comment:10>

Reply all
Reply to author
Forward
0 new messages