Ejemplo n.º 1
0
 def test_remove(self):
     project_state = self.set_up_test_model(self.app_label, index=True)
     table_name = '%s_pony' % self.app_label
     self.assertTableExists(table_name)
     new_state = project_state.clone()
     operation = RemoveIndexConcurrently('Pony', 'pony_pink_idx')
     self.assertEqual(
         operation.describe(),
         'Concurrently remove index pony_pink_idx from Pony',
     )
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, 'pony'].options['indexes']),
         0)
     self.assertIndexExists(table_name, ['pink'])
     # Remove index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(self.app_label, editor, project_state,
                                     new_state)
     self.assertIndexNotExists(table_name, ['pink'])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(self.app_label, editor, new_state,
                                      project_state)
     self.assertIndexExists(table_name, ['pink'])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, 'RemoveIndexConcurrently')
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {
         'model_name': 'Pony',
         'name': 'pony_pink_idx'
     })
Ejemplo n.º 2
0
 def test_remove(self):
     project_state = self.set_up_test_model(self.app_label, index=True)
     table_name = "%s_pony" % self.app_label
     self.assertTableExists(table_name)
     new_state = project_state.clone()
     operation = RemoveIndexConcurrently("Pony", "pony_pink_idx")
     self.assertEqual(
         operation.describe(),
         "Concurrently remove index pony_pink_idx from Pony",
     )
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, "pony"].options["indexes"]), 0
     )
     self.assertIndexExists(table_name, ["pink"])
     # Remove index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(
             self.app_label, editor, project_state, new_state
         )
     self.assertIndexNotExists(table_name, ["pink"])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(
             self.app_label, editor, new_state, project_state
         )
     self.assertIndexExists(table_name, ["pink"])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, "RemoveIndexConcurrently")
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {"model_name": "Pony", "name": "pony_pink_idx"})
Ejemplo n.º 3
0
 def test_requires_atomic_false(self):
     project_state = self.set_up_test_model(self.app_label, index=True)
     new_state = project_state.clone()
     operation = RemoveIndexConcurrently('Pony', 'pony_pink_idx')
     msg = (
         'The RemoveIndexConcurrently operation cannot be executed inside '
         'a transaction (set atomic = False on the migration).')
     with self.assertRaisesMessage(NotSupportedError, msg):
         with connection.schema_editor(atomic=True) as editor:
             operation.database_forwards(self.app_label, editor,
                                         project_state, new_state)
Ejemplo n.º 4
0
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ('analytics', '0009_auto_20200805_0624'),
    ]

    operations = [
        RemoveIndexConcurrently(
            model_name='event', name='analytics_event_name_idx'),
    ]
class Migration(migrations.Migration):

    atomic = False
    dependencies = [
        ('good_flow_app_concurrently', '0002_auto_20191210_2147'),
    ]

    operations = [
        RemoveIndexConcurrently(
            model_name='testtable',
            name='good_flow_a_test_fi_0b7e6f_idx',
        ),
    ]