|
| 1 | +from django.db import migrations, models |
| 2 | + |
| 3 | + |
| 4 | +class Migration(migrations.Migration): |
| 5 | + |
| 6 | + dependencies = [ |
| 7 | + ('tenancy', '0019_contactgroup_comments_tenantgroup_comments'), |
| 8 | + ] |
| 9 | + |
| 10 | + operations = [ |
| 11 | + migrations.SeparateDatabaseAndState( |
| 12 | + state_operations=[ |
| 13 | + # Remove the "through" models from the M2M field |
| 14 | + migrations.AlterField( |
| 15 | + model_name='contact', |
| 16 | + name='groups', |
| 17 | + field=models.ManyToManyField( |
| 18 | + blank=True, |
| 19 | + related_name='contacts', |
| 20 | + related_query_name='contact', |
| 21 | + to='tenancy.contactgroup' |
| 22 | + ), |
| 23 | + ), |
| 24 | + # Remove the ContactGroupMembership model |
| 25 | + migrations.DeleteModel( |
| 26 | + name='ContactGroupMembership', |
| 27 | + ), |
| 28 | + ], |
| 29 | + database_operations=[ |
| 30 | + # Rename ContactGroupMembership table |
| 31 | + migrations.AlterModelTable( |
| 32 | + name='ContactGroupMembership', |
| 33 | + table='tenancy_contact_groups', |
| 34 | + ), |
| 35 | + # Rename the 'group' column (also renames its FK constraint) |
| 36 | + migrations.RenameField( |
| 37 | + model_name='contactgroupmembership', |
| 38 | + old_name='group', |
| 39 | + new_name='contactgroup', |
| 40 | + ), |
| 41 | + # Rename PK sequence |
| 42 | + migrations.RunSQL( |
| 43 | + 'ALTER TABLE tenancy_contactgroupmembership_id_seq ' |
| 44 | + 'RENAME TO tenancy_contact_groups_id_seq' |
| 45 | + ), |
| 46 | + # Rename indexes |
| 47 | + migrations.RunSQL( |
| 48 | + 'ALTER INDEX tenancy_contactgroupmembership_pkey ' |
| 49 | + 'RENAME TO tenancy_contact_groups_pkey' |
| 50 | + ), |
| 51 | + migrations.RunSQL( |
| 52 | + 'ALTER INDEX tenancy_contactgroupmembership_contact_id_04a138a7 ' |
| 53 | + 'RENAME TO tenancy_contact_groups_contact_id_84c9d84f' |
| 54 | + ), |
| 55 | + migrations.RunSQL( |
| 56 | + 'ALTER INDEX tenancy_contactgroupmembership_group_id_bc712dd0 ' |
| 57 | + 'RENAME TO tenancy_contact_groups_contactgroup_id_5c8d6c5a' |
| 58 | + ), |
| 59 | + migrations.RunSQL( |
| 60 | + 'ALTER INDEX unique_group_name ' |
| 61 | + 'RENAME TO tenancy_contact_groups_contact_id_contactgroup_id_f4434f2c_uniq' |
| 62 | + ), |
| 63 | + # Rename foreign key constraint for contact_id |
| 64 | + migrations.RunSQL( |
| 65 | + 'ALTER TABLE tenancy_contact_groups ' |
| 66 | + 'RENAME CONSTRAINT tenancy_contactgroup_contact_id_04a138a7_fk_tenancy_c ' |
| 67 | + 'TO tenancy_contact_grou_contact_id_84c9d84f_fk_tenancy_c' |
| 68 | + ), |
| 69 | + ], |
| 70 | + ), |
| 71 | + ] |
0 commit comments