Esempio n. 1
0
 def test_add(self):
     project_state = self.set_up_test_model(self.app_label, index=False)
     table_name = "%s_pony" % self.app_label
     index = Index(fields=["pink"], name="pony_pink_idx")
     new_state = project_state.clone()
     operation = AddIndexConcurrently("Pony", index)
     self.assertEqual(
         operation.describe(),
         "Concurrently create index pony_pink_idx on field(s) pink of model Pony",
     )
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, "pony"].options["indexes"]), 1
     )
     self.assertIndexNotExists(table_name, ["pink"])
     # Add index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(
             self.app_label, editor, project_state, new_state
         )
     self.assertIndexExists(table_name, ["pink"])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(
             self.app_label, editor, new_state, project_state
         )
     self.assertIndexNotExists(table_name, ["pink"])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, "AddIndexConcurrently")
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {"model_name": "Pony", "index": index})
Esempio n. 2
0
 def test_add(self):
     project_state = self.set_up_test_model(self.app_label, index=False)
     table_name = '%s_pony' % self.app_label
     index = Index(fields=['pink'], name='pony_pink_idx')
     new_state = project_state.clone()
     operation = AddIndexConcurrently('Pony', index)
     self.assertEqual(
         operation.describe(),
         'Concurrently create index pony_pink_idx on field(s) pink of '
         'model Pony')
     operation.state_forwards(self.app_label, new_state)
     self.assertEqual(
         len(new_state.models[self.app_label, 'pony'].options['indexes']),
         1)
     self.assertIndexNotExists(table_name, ['pink'])
     # Add index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(self.app_label, editor, project_state,
                                     new_state)
     self.assertIndexExists(table_name, ['pink'])
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(self.app_label, editor, new_state,
                                      project_state)
     self.assertIndexNotExists(table_name, ['pink'])
     # Deconstruction.
     name, args, kwargs = operation.deconstruct()
     self.assertEqual(name, 'AddIndexConcurrently')
     self.assertEqual(args, [])
     self.assertEqual(kwargs, {'model_name': 'Pony', 'index': index})
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ("zerver", "0278_remove_userprofile_alert_words"),
    ]

    operations = [
        AddIndexConcurrently(
            model_name="message",
            index=models.Index(
                "recipient",
                Upper("subject"),
                F("id").desc(nulls_last=True),
                name="zerver_message_recipient_upper_subject",
            ),
        ),
        AddIndexConcurrently(
            model_name="message",
            index=models.Index(
                "recipient",
                "subject",
                F("id").desc(nulls_last=True),
                name="zerver_message_recipient_subject",
            ),
        ),
    ]
Esempio n. 4
0
 def test_requires_atomic_false(self):
     project_state = self.set_up_test_model(self.app_label)
     new_state = project_state.clone()
     operation = AddIndexConcurrently(
         'Pony',
         Index(fields=['pink'], name='pony_pink_idx'),
     )
     msg = ('The AddIndexConcurrently 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)
class Migration(migrations.Migration):
    atomic = False
    dependencies = [
        ("zerver", "0243_message_add_date_sent_column"),
    ]

    operations = [
        migrations.RunSQL("""
        CREATE FUNCTION zerver_message_date_sent_to_pub_date_trigger_function()
        RETURNS trigger AS $$
        BEGIN
            NEW.date_sent = NEW.pub_date;
            RETURN NEW;
        END
        $$ LANGUAGE 'plpgsql';

        CREATE TRIGGER zerver_message_date_sent_to_pub_date_trigger
        BEFORE INSERT ON zerver_message
        FOR EACH ROW
        EXECUTE PROCEDURE zerver_message_date_sent_to_pub_date_trigger_function();
        """),
        migrations.RunPython(copy_pub_date_to_date_sent, elidable=True),
        AddIndexConcurrently(
            model_name="message",
            index=models.Index("date_sent",
                               name="zerver_message_date_sent_3b5b05d8"),
        ),
    ]
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ("zerver", "0312_subscription_is_user_active"),
    ]

    operations = [
        migrations.RunPython(backfill_is_user_active,
                             reverse_code=migrations.RunPython.noop),
        # Make the field non-null now that we backfilled.
        migrations.AlterField(
            model_name="subscription",
            name="is_user_active",
            field=models.BooleanField(),
        ),
        AddIndexConcurrently(
            model_name="subscription",
            index=models.Index(
                condition=models.Q(("active", True), ("is_user_active", True)),
                fields=["recipient", "user_profile"],
                name="zerver_subscription_recipient_id_user_profile_id_idx",
            ),
        ),
    ]
Esempio n. 7
0
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ('analytics', '0008_auto_20200805_0604'),
    ]

    operations = [
        AddIndexConcurrently(model_name='event',
                             index=models.Index(
                                 fields=['name'],
                                 name='analytics_event_name_idx'))
    ]
Esempio n. 8
0
class Migration(migrations.Migration):

    atomic = False
    dependencies = [
        ('good_flow_app_concurrently', '0001_initial'),
    ]

    operations = [
        AddIndexConcurrently(
            model_name='testtable',
            index=models.Index(fields=['test_field_int'], name='good_flow_a_test_fi_0b7e6f_idx'),
        ),
    ]
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ("posthog", "0109_fix_retention_filters"),
    ]

    operations = [
        AddIndexConcurrently(
            model_name="sessionrecordingevent",
            index=models.Index(fields=["team_id", "timestamp"],
                               name="posthog_ses_team_id_0409c4_idx"),
        ),
    ]
class Migration(migrations.Migration):
    atomic = False

    dependencies = [
        ("posthog", "0140_team_data_attributes"),
    ]

    operations = [
        AddIndexConcurrently(
            model_name="event",
            index=models.Index(fields=["created_at"],
                               name="posthog_eve_created_6a34ca_idx"),
        ),
    ]
Esempio n. 11
0
 def test_add_with_options(self):
     project_state = self.set_up_test_model(self.app_label, index=False)
     table_name = '%s_pony' % self.app_label
     new_state = project_state.clone()
     index = BTreeIndex(fields=['pink'],
                        name='pony_pink_btree_idx',
                        fillfactor=70)
     operation = AddIndexConcurrently('Pony', index)
     self.assertIndexNotExists(table_name, ['pink'])
     # Add index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(self.app_label, editor, project_state,
                                     new_state)
     self.assertIndexExists(table_name, ['pink'], index_type='btree')
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(self.app_label, editor, new_state,
                                      project_state)
     self.assertIndexNotExists(table_name, ['pink'])
Esempio n. 12
0
 def test_add_other_index_type(self):
     project_state = self.set_up_test_model(self.app_label, index=False)
     table_name = "%s_pony" % self.app_label
     new_state = project_state.clone()
     operation = AddIndexConcurrently(
         "Pony",
         BrinIndex(fields=["pink"], name="pony_pink_brin_idx"),
     )
     self.assertIndexNotExists(table_name, ["pink"])
     # Add index.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_forwards(self.app_label, editor, project_state,
                                     new_state)
     self.assertIndexExists(table_name, ["pink"], index_type="brin")
     # Reversal.
     with connection.schema_editor(atomic=False) as editor:
         operation.database_backwards(self.app_label, editor, new_state,
                                      project_state)
     self.assertIndexNotExists(table_name, ["pink"])