<reponame>bishtamit/django-searchable-encrypted-fields<filename>encrypted_fields_test/migrations/0005_data_migration_example_2.py
# Generated by Django 2.1 on 2020-10-03 17:10

from django.db import migrations


def migrate_data(apps, schema_editor):
    """Demonstrates migrating from an EncryptedCharField -> SearchField (with a
    different associated EncryptedCharField).

    *IMPORTANT!* Never add a SearchField and point it to an *existing* EncryptedField,
    or you will lose all your data!

    This process is basically the same as for regular CharField -> SearchField."""
    demo_migration_model = apps.get_model('encrypted_fields_test', 'DemoMigrationModel')
    for obj in demo_migration_model.objects.all():
        obj.searchable_encrypted_data = obj.encrypted_data
        obj.save()
        # Note: the value is now encrypted and saved in 'obj._encrypted_data'
        # The old 'encrypted_data' field could be removed in a later migration.


class Migration(migrations.Migration):

    dependencies = [
        ('encrypted_fields_test', '0004_data_migration_example'),
    ]

    operations = [
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]

# Generated by Django 2.1 on 2020-10-03 17:10

from django.db import migrations


def migrate_data(apps, schema_editor):
    """Demonstrates migrating from an EncryptedCharField -> SearchField (with a
    different associated EncryptedCharField).

    *IMPORTANT!* Never add a SearchField and point it to an *existing* EncryptedField,
    or you will lose all your data!

    This process is basically the same as for regular CharField -> SearchField."""
    demo_migration_model = apps.get_model('encrypted_fields_test', 'DemoMigrationModel')
    for obj in demo_migration_model.objects.all():
        obj.searchable_encrypted_data = obj.encrypted_data
        obj.save()
        # Note: the value is now encrypted and saved in 'obj._encrypted_data'
        # The old 'encrypted_data' field could be removed in a later migration.


class Migration(migrations.Migration):

    dependencies = [
        ('encrypted_fields_test', '0004_data_migration_example'),
    ]

    operations = [
        migrations.RunPython(migrate_data, reverse_code=migrations.RunPython.noop),
    ]
# Generated by Django 2.1 on 2020-10-03 17:10 Demonstrates migrating from an EncryptedCharField -> SearchField (with a     different associated EncryptedCharField).      *IMPORTANT!* Never add a SearchField and point it to an *existing* EncryptedField,     or you will lose all your data!      This process is basically the same as for regular CharField -> SearchField. # Note: the value is now encrypted and saved in 'obj._encrypted_data' # The old 'encrypted_data' field could be removed in a later migration.