Bring back cached_render_for_web (#262)
This commit is contained in:
parent
4420414faa
commit
eeba2f5b31
3 changed files with 64 additions and 8 deletions
|
|
@ -4,18 +4,25 @@ from django.db import migrations
|
|||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
"""
|
||||
The previous version of this migration removes two fields:
|
||||
cached_render_for_web and active_cache_for_web_calculation_id.
|
||||
Now it doesn't do anything because it can be very slow and even fail on write heavy alertgroup table.
|
||||
This migration was released in version 1.0.7, so in order to bring back these fields in the later version
|
||||
there's a 0005 migration. Please see the next migration in alerts: 0005_alertgroup_cached_render_for_web.py
|
||||
"""
|
||||
|
||||
dependencies = [
|
||||
('alerts', '0003_grafanaalertingcontactpoint_datasource_uid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='alertgroup',
|
||||
name='active_cache_for_web_calculation_id',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='alertgroup',
|
||||
name='cached_render_for_web',
|
||||
),
|
||||
# migrations.RemoveField(
|
||||
# model_name='alertgroup',
|
||||
# name='active_cache_for_web_calculation_id',
|
||||
# ),
|
||||
# migrations.RemoveField(
|
||||
# model_name='alertgroup',
|
||||
# name='cached_render_for_web',
|
||||
# ),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
# Generated by Django 3.2.13 on 2022-07-20 09:04
|
||||
|
||||
from django.db import migrations, models, OperationalError
|
||||
|
||||
|
||||
class AddFieldIfNotExists(migrations.AddField):
|
||||
"""
|
||||
Adds a field and ignores "duplicate column" error in case the field already exists.
|
||||
When migrating back it will not delete the field.
|
||||
"""
|
||||
|
||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||
try:
|
||||
super().database_forwards(app_label, schema_editor, from_state, to_state)
|
||||
except OperationalError:
|
||||
pass
|
||||
|
||||
def database_backwards(self, app_label, schema_editor, from_state, to_state):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
"""
|
||||
This migration tries to create two fields cached_render_for_web and active_cache_for_web_calculation_id.
|
||||
In case these fields already exist, this migration will do nothing.
|
||||
In case the database was already affected by the previous version of the 0004 migration,
|
||||
it will recreate these fields.
|
||||
"""
|
||||
|
||||
dependencies = [
|
||||
('alerts', '0004_auto_20220711_1106'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
AddFieldIfNotExists(
|
||||
model_name='alertgroup',
|
||||
name='cached_render_for_web',
|
||||
field=models.JSONField(default=dict),
|
||||
),
|
||||
AddFieldIfNotExists(
|
||||
model_name='alertgroup',
|
||||
name='active_cache_for_web_calculation_id',
|
||||
field=models.CharField(default=None, max_length=100, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -299,6 +299,10 @@ class AlertGroup(AlertGroupSlackRenderingMixin, EscalationSnapshotMixin, models.
|
|||
related_name="dependent_alert_groups",
|
||||
)
|
||||
|
||||
# cached_render_for_web and active_cache_for_web_calculation_id are deprecated
|
||||
cached_render_for_web = models.JSONField(default=dict)
|
||||
active_cache_for_web_calculation_id = models.CharField(max_length=100, null=True, default=None)
|
||||
|
||||
last_unique_unacknowledge_process_id = models.CharField(max_length=100, null=True, default=None)
|
||||
is_archived = models.BooleanField(default=False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue