mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Altering events relationship to hosts to increase performance (#12447)
Removing cascade on delete at model level that could cause locking issues.
This commit is contained in:
parent
35afb10add
commit
b84a192bad
40
awx/main/migrations/0166_alter_jobevent_host.py
Normal file
40
awx/main/migrations/0166_alter_jobevent_host.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Generated by Django 3.2.13 on 2022-07-06 13:19
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0165_task_manager_refactor'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='adhoccommandevent',
|
||||
name='host',
|
||||
field=models.ForeignKey(
|
||||
db_constraint=False,
|
||||
default=None,
|
||||
editable=False,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name='ad_hoc_command_events',
|
||||
to='main.host',
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='jobevent',
|
||||
name='host',
|
||||
field=models.ForeignKey(
|
||||
db_constraint=False,
|
||||
default=None,
|
||||
editable=False,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name='job_events_as_primary_host',
|
||||
to='main.host',
|
||||
),
|
||||
),
|
||||
]
|
||||
@ -25,7 +25,6 @@ analytics_logger = logging.getLogger('awx.analytics.job_events')
|
||||
|
||||
logger = logging.getLogger('awx.main.models.events')
|
||||
|
||||
|
||||
__all__ = ['JobEvent', 'ProjectUpdateEvent', 'AdHocCommandEvent', 'InventoryUpdateEvent', 'SystemJobEvent']
|
||||
|
||||
|
||||
@ -486,13 +485,18 @@ class JobEvent(BasePlaybookEvent):
|
||||
editable=False,
|
||||
db_index=False,
|
||||
)
|
||||
# When we partitioned the table we accidentally "lost" the foreign key constraint.
|
||||
# However this is good because the cascade on delete at the django layer was causing DB issues
|
||||
# We are going to leave this as a foreign key but mark it as not having a DB relation and
|
||||
# prevent cascading on delete.
|
||||
host = models.ForeignKey(
|
||||
'Host',
|
||||
related_name='job_events_as_primary_host',
|
||||
null=True,
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
on_delete=models.DO_NOTHING,
|
||||
editable=False,
|
||||
db_constraint=False,
|
||||
)
|
||||
host_name = models.CharField(
|
||||
max_length=1024,
|
||||
@ -794,6 +798,10 @@ class AdHocCommandEvent(BaseCommandEvent):
|
||||
editable=False,
|
||||
db_index=False,
|
||||
)
|
||||
# We need to keep this as a FK in the model because AdHocCommand uses a ManyToMany field
|
||||
# to hosts through adhoc_events. But in https://github.com/ansible/awx/pull/8236/ we
|
||||
# removed the nulling of the field in case of a host going away before an event is saved
|
||||
# so this needs to stay SET_NULL on the ORM level
|
||||
host = models.ForeignKey(
|
||||
'Host',
|
||||
related_name='ad_hoc_command_events',
|
||||
@ -801,6 +809,7 @@ class AdHocCommandEvent(BaseCommandEvent):
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
editable=False,
|
||||
db_constraint=False,
|
||||
)
|
||||
host_name = models.CharField(
|
||||
max_length=1024,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user