mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[3.0.x] Fixed #30870 -- Fixed showing that RunPython operations are irreversible by migrate --plan.
Thanks Hasan Ramezani for the initial patch and Kyle Dickerson for the
report.
Backport of 06d34aab7c from master
This commit is contained in:
@@ -371,6 +371,28 @@ class MigrateTests(MigrationTestBase):
|
||||
' Raw SQL operation -> IRREVERSIBLE\n',
|
||||
out.getvalue()
|
||||
)
|
||||
out = io.StringIO()
|
||||
call_command('migrate', 'migrations', '0005', plan=True, stdout=out, no_color=True)
|
||||
# Operation is marked as irreversible only in the revert plan.
|
||||
self.assertEqual(
|
||||
'Planned operations:\n'
|
||||
'migrations.0005_fifth\n'
|
||||
' Raw Python operation\n'
|
||||
' Raw Python operation\n'
|
||||
' Raw Python operation -> Feed salamander.\n',
|
||||
out.getvalue()
|
||||
)
|
||||
call_command('migrate', 'migrations', '0005', verbosity=0)
|
||||
out = io.StringIO()
|
||||
call_command('migrate', 'migrations', '0004', plan=True, stdout=out, no_color=True)
|
||||
self.assertEqual(
|
||||
'Planned operations:\n'
|
||||
'migrations.0005_fifth\n'
|
||||
' Raw Python operation -> IRREVERSIBLE\n'
|
||||
' Raw Python operation -> IRREVERSIBLE\n'
|
||||
' Raw Python operation\n',
|
||||
out.getvalue()
|
||||
)
|
||||
finally:
|
||||
# Cleanup by unmigrating everything: fake the irreversible, then
|
||||
# migrate all to zero.
|
||||
|
||||
22
tests/migrations/test_migrations_plan/0005_fifth.py
Normal file
22
tests/migrations/test_migrations_plan/0005_fifth.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def grow_tail(x, y):
|
||||
pass
|
||||
|
||||
|
||||
def feed(x, y):
|
||||
"""Feed salamander."""
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('migrations', '0004_fourth'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrations.RunPython.noop),
|
||||
migrations.RunPython(grow_tail),
|
||||
migrations.RunPython(feed, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user