38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
from django.db import migrations, models
|
|
from django.utils import timezone
|
|
|
|
|
|
class CreateAuditModel(migrations.CreateModel):
|
|
"""0008 can create this audit table before repairing legacy data.
|
|
|
|
Existing installations that already applied 0008 create it here instead.
|
|
Keep audit history on rollback; it is evidence of irreversible data repairs.
|
|
"""
|
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
|
model = to_state.apps.get_model(app_label, self.name)
|
|
if model._meta.db_table not in schema_editor.connection.introspection.table_names():
|
|
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
|
|
|
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
|
pass
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [('customer', '0008_customer_mobile_unique')]
|
|
operations = [CreateAuditModel(
|
|
name='MobileConflict',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('source_model', models.CharField(max_length=100)),
|
|
('record_id', models.PositiveBigIntegerField()),
|
|
('workspace_id', models.PositiveBigIntegerField(null=True, blank=True)),
|
|
('original_mobile', models.PositiveBigIntegerField(null=True, blank=True)),
|
|
('canonical_mobile', models.PositiveBigIntegerField()),
|
|
('snapshot', models.JSONField()),
|
|
('created_at', models.DateTimeField(default=timezone.now, editable=False)),
|
|
],
|
|
options={'ordering': ['-created_at', '-pk'],
|
|
'unique_together': (('source_model', 'record_id'),),
|
|
'verbose_name': 'تعارض شماره قدیمی', 'verbose_name_plural': 'تعارضهای شماره قدیمی'},
|
|
)]
|