From 2d07e1aaebadbd576ee2a055760a5866d4408a87 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 27 Dec 2021 18:49:19 +0100 Subject: [PATCH] Refs #22983 -- Added tests for squashing migrations with functions from migration files. Follow up to ebb13bbd884d8c3053d1d342ef0423240feb05e6. --- tests/migrations/test_commands.py | 36 +++++++++++++++++++ .../0001_initial.py | 15 ++++++++ .../0002_second.py | 15 ++++++++ .../__init__.py | 0 4 files changed, 66 insertions(+) create mode 100644 tests/migrations/test_migrations_manual_porting/0001_initial.py create mode 100644 tests/migrations/test_migrations_manual_porting/0002_second.py create mode 100644 tests/migrations/test_migrations_manual_porting/__init__.py diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index ebaaccb1db..bf78b60a85 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -2131,6 +2131,42 @@ class SquashMigrationsTests(MigrationTestBase): squashed_name='initial', interactive=False, verbosity=0, ) + def test_squashmigrations_manual_porting(self): + out = io.StringIO() + with self.temporary_migration_module( + module='migrations.test_migrations_manual_porting', + ) as migration_dir: + call_command( + 'squashmigrations', + 'migrations', + '0002', + interactive=False, + stdout=out, + no_color=True, + ) + squashed_migration_file = os.path.join( + migration_dir, + '0001_squashed_0002_second.py', + ) + self.assertTrue(os.path.exists(squashed_migration_file)) + self.assertEqual( + out.getvalue(), + f'Will squash the following migrations:\n' + f' - 0001_initial\n' + f' - 0002_second\n' + f'Optimizing...\n' + f' No optimizations possible.\n' + f'Created new squashed migration {squashed_migration_file}\n' + f' You should commit this migration but leave the old ones in place;\n' + f' the new migration will be used for new installs. Once you are sure\n' + f' all instances of the codebase have applied the migrations you squashed,\n' + f' you can delete them.\n' + f'Manual porting required\n' + f' Your migrations contained functions that must be manually copied over,\n' + f' as we could not safely copy their implementation.\n' + f' See the comment at the top of the squashed migration for details.\n' + ) + class AppLabelErrorTests(TestCase): """ diff --git a/tests/migrations/test_migrations_manual_porting/0001_initial.py b/tests/migrations/test_migrations_manual_porting/0001_initial.py new file mode 100644 index 0000000000..c3e03d6f07 --- /dev/null +++ b/tests/migrations/test_migrations_manual_porting/0001_initial.py @@ -0,0 +1,15 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + operations = [ + migrations.CreateModel( + 'SomeModel', + [ + ('id', models.AutoField(primary_key=True)), + ('name', models.CharField(max_length=255)), + ], + ), + ] diff --git a/tests/migrations/test_migrations_manual_porting/0002_second.py b/tests/migrations/test_migrations_manual_porting/0002_second.py new file mode 100644 index 0000000000..78ab9eebeb --- /dev/null +++ b/tests/migrations/test_migrations_manual_porting/0002_second.py @@ -0,0 +1,15 @@ +from django.db import migrations + + +def forwards(apps, schema_editor): + pass + + +class Migration(migrations.Migration): + dependencies = [ + ('migrations', '0001_initial'), + ] + + operations = [ + migrations.RunPython(forwards, migrations.RunPython.noop), + ] diff --git a/tests/migrations/test_migrations_manual_porting/__init__.py b/tests/migrations/test_migrations_manual_porting/__init__.py new file mode 100644 index 0000000000..e69de29bb2