mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Replicate JobResults to new Job model
This commit is contained in:
parent
34236ff468
commit
b3d2020045
@ -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)),
|
45
netbox/core/migrations/0004_replicate_jobresults.py
Normal file
45
netbox/core/migrations/0004_replicate_jobresults.py
Normal 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
|
||||
),
|
||||
]
|
18
netbox/core/migrations/0005_job_created_auto_now.py
Normal file
18
netbox/core/migrations/0005_job_created_auto_now.py
Normal 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),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user