Replicate JobResults to new Job model

This commit is contained in:
jeremystretch 2023-03-27 12:32:44 -04:00 committed by Jeremy Stretch
parent 34236ff468
commit b3d2020045
3 changed files with 64 additions and 1 deletions

View File

@ -22,7 +22,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('object_id', models.PositiveBigIntegerField(blank=True, null=True)),
('name', models.CharField(max_length=200)),
('created', models.DateTimeField(auto_now_add=True)),
('created', models.DateTimeField()),
('scheduled', models.DateTimeField(blank=True, null=True)),
('interval', models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1)])),
('started', models.DateTimeField(blank=True, null=True)),

View File

@ -0,0 +1,45 @@
from django.db import migrations
def replicate_jobresults(apps, schema_editor):
"""
Replicate existing JobResults to the new Jobs table before deleting the old JobResults table.
"""
Job = apps.get_model('core', 'Job')
JobResult = apps.get_model('extras', 'JobResult')
jobs = []
for job_result in JobResult.objects.iterator(chunk_size=100):
jobs.append(
Job(
object_type=job_result.obj_type,
name=job_result.name,
created=job_result.created,
scheduled=job_result.scheduled,
interval=job_result.interval,
started=job_result.started,
completed=job_result.completed,
user=job_result.user,
status=job_result.status,
data=job_result.data,
job_id=job_result.job_id,
)
)
if len(jobs) == 100:
Job.objects.bulk_create(jobs)
if jobs:
Job.objects.bulk_create(jobs)
class Migration(migrations.Migration):
dependencies = [
('core', '0003_job'),
]
operations = [
migrations.RunPython(
code=replicate_jobresults,
reverse_code=migrations.RunPython.noop
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-03-27 17:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_replicate_jobresults'),
]
operations = [
migrations.AlterField(
model_name='job',
name='created',
field=models.DateTimeField(auto_now_add=True),
),
]