Re-planning a full migration of a fully-migrated set doesn't perform spurious unmigrations and remigrations. There was previously a bug where the executor just always performed the backwards plan for applied migrations - which even for the most recent migrat
(self)
| 196 | } |
| 197 | ) |
| 198 | def test_empty_plan(self): |
| 199 | """ |
| 200 | Re-planning a full migration of a fully-migrated set doesn't |
| 201 | perform spurious unmigrations and remigrations. |
| 202 | |
| 203 | There was previously a bug where the executor just always performed the |
| 204 | backwards plan for applied migrations - which even for the most recent |
| 205 | migration in an app, might include other, dependent apps, and these |
| 206 | were being unmigrated. |
| 207 | """ |
| 208 | # Make the initial plan, check it |
| 209 | executor = MigrationExecutor(connection) |
| 210 | plan = executor.migration_plan( |
| 211 | [ |
| 212 | ("migrations", "0002_second"), |
| 213 | ("migrations2", "0001_initial"), |
| 214 | ] |
| 215 | ) |
| 216 | self.assertEqual( |
| 217 | plan, |
| 218 | [ |
| 219 | (executor.loader.graph.nodes["migrations", "0001_initial"], False), |
| 220 | (executor.loader.graph.nodes["migrations", "0002_second"], False), |
| 221 | (executor.loader.graph.nodes["migrations2", "0001_initial"], False), |
| 222 | ], |
| 223 | ) |
| 224 | # Fake-apply all migrations |
| 225 | executor.migrate( |
| 226 | [("migrations", "0002_second"), ("migrations2", "0001_initial")], fake=True |
| 227 | ) |
| 228 | # Rebuild the graph to reflect the new DB state |
| 229 | executor.loader.build_graph() |
| 230 | # Now plan a second time and make sure it's empty |
| 231 | plan = executor.migration_plan( |
| 232 | [ |
| 233 | ("migrations", "0002_second"), |
| 234 | ("migrations2", "0001_initial"), |
| 235 | ] |
| 236 | ) |
| 237 | self.assertEqual(plan, []) |
| 238 | # The resulting state should include applied migrations. |
| 239 | state = executor.migrate( |
| 240 | [ |
| 241 | ("migrations", "0002_second"), |
| 242 | ("migrations2", "0001_initial"), |
| 243 | ] |
| 244 | ) |
| 245 | self.assertIn(("migrations", "book"), state.models) |
| 246 | self.assertIn(("migrations", "author"), state.models) |
| 247 | self.assertIn(("migrations2", "otherauthor"), state.models) |
| 248 | # Erase all the fake records |
| 249 | executor.recorder.record_unapplied("migrations2", "0001_initial") |
| 250 | executor.recorder.record_unapplied("migrations", "0002_second") |
| 251 | executor.recorder.record_unapplied("migrations", "0001_initial") |
| 252 | |
| 253 | @override_settings( |
| 254 | MIGRATION_MODULES={ |
nothing calls this directly
no test coverage detected