Python django.db.migrations.RemoveIndex() Examples

The following are 8 code examples of django.db.migrations.RemoveIndex(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db.migrations , or try the search function .
Example #1
Source File: test_operations.py    From django-sqlserver with MIT License 6 votes vote down vote up
def test_indexes_ignore_swapped(self):
        """
        Add/RemoveIndex operations ignore swapped models.
        """
        operation = migrations.AddIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state('test_adinigsw', operation)
        with connection.schema_editor() as editor:
            # No database queries should be run for swapped models
            operation.database_forwards('test_adinigsw', editor, project_state, new_state)
            operation.database_backwards('test_adinigsw', editor, new_state, project_state)

        operation = migrations.RemoveIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state("test_rminigsw", operation)
        with connection.schema_editor() as editor:
            operation.database_forwards('test_rminigsw', editor, project_state, new_state)
            operation.database_backwards('test_rminigsw', editor, new_state, project_state) 
Example #2
Source File: test_operations.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_indexes_ignore_swapped(self):
        """
        Add/RemoveIndex operations ignore swapped models.
        """
        operation = migrations.AddIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state('test_adinigsw', operation)
        with connection.schema_editor() as editor:
            # No database queries should be run for swapped models
            operation.database_forwards('test_adinigsw', editor, project_state, new_state)
            operation.database_backwards('test_adinigsw', editor, new_state, project_state)

        operation = migrations.RemoveIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state("test_rminigsw", operation)
        with connection.schema_editor() as editor:
            operation.database_forwards('test_rminigsw', editor, project_state, new_state)
            operation.database_backwards('test_rminigsw', editor, new_state, project_state) 
Example #3
Source File: test_operations.py    From django-sqlserver with MIT License 5 votes vote down vote up
def test_remove_index_state_forwards(self):
        project_state = self.set_up_test_model('test_rminsf')
        index = models.Index(fields=['pink'], name='test_rminsf_pony_pink_idx')
        migrations.AddIndex('Pony', index).state_forwards('test_rminsf', project_state)
        old_model = project_state.apps.get_model('test_rminsf', 'Pony')
        new_state = project_state.clone()

        operation = migrations.RemoveIndex('Pony', 'test_rminsf_pony_pink_idx')
        operation.state_forwards('test_rminsf', new_state)
        new_model = new_state.apps.get_model('test_rminsf', 'Pony')
        self.assertIsNot(old_model, new_model) 
Example #4
Source File: test_operations.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_remove_index_state_forwards(self):
        project_state = self.set_up_test_model('test_rminsf')
        index = models.Index(fields=['pink'], name='test_rminsf_pony_pink_idx')
        migrations.AddIndex('Pony', index).state_forwards('test_rminsf', project_state)
        old_model = project_state.apps.get_model('test_rminsf', 'Pony')
        new_state = project_state.clone()

        operation = migrations.RemoveIndex('Pony', 'test_rminsf_pony_pink_idx')
        operation.state_forwards('test_rminsf', new_state)
        new_model = new_state.apps.get_model('test_rminsf', 'Pony')
        self.assertIsNot(old_model, new_model) 
Example #5
Source File: test_operations.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_remove_index_state_forwards(self):
        project_state = self.set_up_test_model('test_rminsf')
        index = models.Index(fields=['pink'], name='test_rminsf_pony_pink_idx')
        migrations.AddIndex('Pony', index).state_forwards('test_rminsf', project_state)
        old_model = project_state.apps.get_model('test_rminsf', 'Pony')
        new_state = project_state.clone()

        operation = migrations.RemoveIndex('Pony', 'test_rminsf_pony_pink_idx')
        operation.state_forwards('test_rminsf', new_state)
        new_model = new_state.apps.get_model('test_rminsf', 'Pony')
        self.assertIsNot(old_model, new_model) 
Example #6
Source File: test_operations.py    From django-sqlserver with MIT License 4 votes vote down vote up
def test_remove_index(self):
        """
        Test the RemoveIndex operation.
        """
        project_state = self.set_up_test_model("test_rmin", multicol_index=True)
        self.assertTableExists("test_rmin_pony")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        operation = migrations.RemoveIndex("Pony", "pony_test_idx")
        self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_rmin", new_state)
        # Test the state alteration
        self.assertEqual(len(new_state.models["test_rmin", "pony"].options['indexes']), 0)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test the database alteration
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmin", editor, project_state, new_state)
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_rmin", editor, new_state, project_state)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "RemoveIndex")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'model_name': "Pony", 'name': "pony_test_idx"})

        # Also test a field dropped with index - sqlite remake issue
        operations = [
            migrations.RemoveIndex("Pony", "pony_test_idx"),
            migrations.RemoveField("Pony", "pink"),
        ]
        self.assertColumnExists("test_rmin_pony", "pink")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test database alteration
        new_state = project_state.clone()
        self.apply_operations('test_rmin', new_state, operations=operations)
        self.assertColumnNotExists("test_rmin_pony", "pink")
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        self.unapply_operations("test_rmin", project_state, operations=operations)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"]) 
Example #7
Source File: test_operations.py    From djongo with GNU Affero General Public License v3.0 4 votes vote down vote up
def test_remove_index(self):
        """
        Test the RemoveIndex operation.
        """
        project_state = self.set_up_test_model("test_rmin", multicol_index=True)
        self.assertTableExists("test_rmin_pony")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        operation = migrations.RemoveIndex("Pony", "pony_test_idx")
        self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_rmin", new_state)
        # Test the state alteration
        self.assertEqual(len(new_state.models["test_rmin", "pony"].options['indexes']), 0)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test the database alteration
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmin", editor, project_state, new_state)
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_rmin", editor, new_state, project_state)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "RemoveIndex")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'model_name': "Pony", 'name': "pony_test_idx"})

        # Also test a field dropped with index - sqlite remake issue
        operations = [
            migrations.RemoveIndex("Pony", "pony_test_idx"),
            migrations.RemoveField("Pony", "pink"),
        ]
        self.assertColumnExists("test_rmin_pony", "pink")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test database alteration
        new_state = project_state.clone()
        self.apply_operations('test_rmin', new_state, operations=operations)
        self.assertColumnNotExists("test_rmin_pony", "pink")
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        self.unapply_operations("test_rmin", project_state, operations=operations)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"]) 
Example #8
Source File: test_operations.py    From djongo with GNU Affero General Public License v3.0 4 votes vote down vote up
def test_remove_index(self):
        """
        Test the RemoveIndex operation.
        """
        project_state = self.set_up_test_model("test_rmin", multicol_index=True)
        self.assertTableExists("test_rmin_pony")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        operation = migrations.RemoveIndex("Pony", "pony_test_idx")
        self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_rmin", new_state)
        # Test the state alteration
        self.assertEqual(len(new_state.models["test_rmin", "pony"].options['indexes']), 0)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test the database alteration
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmin", editor, project_state, new_state)
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_rmin", editor, new_state, project_state)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "RemoveIndex")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'model_name': "Pony", 'name': "pony_test_idx"})

        # Also test a field dropped with index - sqlite remake issue
        operations = [
            migrations.RemoveIndex("Pony", "pony_test_idx"),
            migrations.RemoveField("Pony", "pink"),
        ]
        self.assertColumnExists("test_rmin_pony", "pink")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test database alteration
        new_state = project_state.clone()
        self.apply_operations('test_rmin', new_state, operations=operations)
        self.assertColumnNotExists("test_rmin_pony", "pink")
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        self.unapply_operations("test_rmin", project_state, operations=operations)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])