Skip to content

Commit df9d118

Browse files
committed
allow clearing migration targets
1 parent 093066e commit df9d118

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

admin/management/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def post(self, request):
202202
'no_color': True,
203203
'no_counts': request.POST.get('no_counts'),
204204
'clear_state': request.POST.get('clear_state'),
205+
'clear_es8_data': request.POST.get('clear_es8_data'),
205206
'start': request.POST.get('start'),
206207
'unchanged': request.POST.get('unchanged'),
207208
'usage_reports': request.POST.get('usage_reports'),

admin/templates/management/commands.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ <h4><u>migrate osf-metrics 6to8</u></h4>
187187
action="{% url 'management:migrate_osfmetrics_6to8'%}"
188188
style="display: flex; flex-direction: column;">
189189
{% csrf_token %}
190-
<label><input type="checkbox" name="start"> start tasks (caution)</label>
191190
<label><input type="checkbox" name="no_counts"> no counts</label>
191+
<label><input type="checkbox" name="start"> start tasks (caution)</label>
192192
<label><input type="checkbox" name="clear_state"> reset migration start time (caution)</label>
193+
<label><input type="checkbox" name="clear_es8_data"> clear es8 data (big caution)</label>
193194
<fieldset>
194195
(narrow types:
195196
<label><input type="checkbox" name="unchanged"> unchanged events and reports</label>

osf/management/commands/migrate_osfmetrics_6to8.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,10 @@ def add_arguments(self, parser):
575575
'--clear-state',
576576
action='store_true',
577577
)
578+
parser.add_argument(
579+
'--clear-es8-data',
580+
action='store_true',
581+
)
578582
parser.add_argument(
579583
'--start',
580584
action='store_true',
@@ -602,6 +606,7 @@ def handle(
602606
no_setup,
603607
no_counts,
604608
clear_state,
609+
clear_es8_data,
605610
start,
606611
unchanged,
607612
usage_events,
@@ -613,6 +618,8 @@ def handle(
613618
call_command('djelme_backend_setup')
614619
if clear_state:
615620
self._clear_state()
621+
if clear_es8_data:
622+
self._clear_es8_data(unchanged, usage_events, usage_reports)
616623
self._check_started_at(start_now=start)
617624
_default_all = not any((unchanged, usage_events, usage_reports))
618625
if unchanged or _default_all:
@@ -754,6 +761,22 @@ def _clear_state(self):
754761
es8_metrics.Elastic6To8State.search().query({'match_all': {}}).delete()
755762
es8_metrics.Elastic6To8State.refresh()
756763

764+
def _clear_es8_data(self, unchanged, usage_events, usage_reports):
765+
_default_all = not any((unchanged, usage_events, usage_reports))
766+
_to_clear = []
767+
if _default_all or unchanged:
768+
_to_clear.extend(_UNCHANGED_RECORDTYPES.values())
769+
if _default_all or usage_events:
770+
_to_clear.append(es8_metrics.MonthlyPublicItemUsageReportEs8)
771+
if _default_all or usage_reports:
772+
_to_clear.append(es8_metrics.OsfCountedUsageEvent)
773+
for _es8_recordtype in _to_clear:
774+
self.stdout.write(
775+
f'clearing {_es8_recordtype.__name__}', self.style.NOTICE
776+
)
777+
_es8_recordtype.search().query({'match_all': {}}).delete()
778+
_es8_recordtype.refresh()
779+
757780
def _eq_style(self, num: int, should_be: int):
758781
return self.style.SUCCESS if (num == should_be) else self.style.WARNING
759782

0 commit comments

Comments
 (0)