def database_forwards(self, app_label, schema_editor, from_state, to_state): """Perform forward migration.""" from resolwe.flow.models.base import delete_chunked Data = from_state.apps.get_model("flow", "Data") delete_chunked(Data.objects.filter(process__persistence="TMP")) delete_chunked(Data.objects.filter(status="ER"))
def database_forwards(self, app_label, schema_editor, from_state, to_state): """Perform forward migration.""" from resolwe.flow.models.base import delete_chunked Data = from_state.apps.get_model("flow", "Data") delete_chunked(Data.objects.filter(process__slug=self.process)) Process = from_state.apps.get_model("flow", "Process") Process.objects.filter(slug=self.process).delete()
def delete_unreferenced_storages(apps, schema_editor): Data = apps.get_model("flow", "Data") Storage = apps.get_model("flow", "Storage") for data in Data.objects.iterator(): referenced_storages = [] for field_schema, fields in iterate_fields( data.output, data.process.output_schema ): if field_schema["type"].startswith("basic:json:"): name = field_schema["name"] referenced_storages.append(fields[name]) data.storages.remove(*data.storages.exclude(pk__in=referenced_storages)) delete_chunked(Storage.objects.filter(data__isnull=True), chunk_size=100)