From 23dfdfe0b38c82feec77a9db436f6f8986c5ff0e Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 20 May 2025 05:09:37 +0930 Subject: [PATCH] chore(core): remove old manual migration no longer required ref: #765 --- .../0014_data_move_notes_to_new_table.py | 86 ++-- .../0016_data_move_history_to_new_table.py | 460 +++++++++--------- 2 files changed, 273 insertions(+), 273 deletions(-) diff --git a/app/core/migrations/0014_data_move_notes_to_new_table.py b/app/core/migrations/0014_data_move_notes_to_new_table.py index cb612d2b..d869e5c1 100644 --- a/app/core/migrations/0014_data_move_notes_to_new_table.py +++ b/app/core/migrations/0014_data_move_notes_to_new_table.py @@ -8,15 +8,15 @@ from django.db import migrations, models from django.contrib.auth.models import User, ContentType -from core.models.notes import Notes +# from core.models.notes import Notes -from config_management.models.config_group_notes import ConfigGroupNotes +# from config_management.models.config_group_notes import ConfigGroupNotes -from itam.models.device_notes import DeviceNotes -from itam.models.operating_system_notes import OperatingSystemNotes -from itam.models.software_notes import SoftwareNotes +# from itam.models.device_notes import DeviceNotes +# from itam.models.operating_system_notes import OperatingSystemNotes +# from itam.models.software_notes import SoftwareNotes -from itim.models.service_notes import ServiceNotes +# from itim.models.service_notes import ServiceNotes def move_notes(apps, schema_editor): @@ -26,62 +26,62 @@ def move_notes(apps, schema_editor): # ) print(f"migtating notes data to new notes tables.....") - model_notes = Notes.objects.all() + # model_notes = Notes.objects.all() - for note in model_notes: + # for note in model_notes: - if not note.usercreated: + # if not note.usercreated: - print(f"*********************** ERROR ***********************") - print(f" NOT migtating note {note.id}, as no creation user exists.") - print(f" - Note contents: {note.note}") - print(f"********************* EoF ERROR *********************") + # print(f"*********************** ERROR ***********************") + # print(f" NOT migtating note {note.id}, as no creation user exists.") + # print(f" - Note contents: {note.note}") + # print(f"********************* EoF ERROR *********************") - continue + # continue - print(f" migtating note {note.id}") + # print(f" migtating note {note.id}") - if note.config_group: + # if note.config_group: - note_item_model = note.config_group - note_model = ConfigGroupNotes + # note_item_model = note.config_group + # note_model = ConfigGroupNotes - elif note.device: + # elif note.device: - note_item_model = note.device - note_model = DeviceNotes + # note_item_model = note.device + # note_model = DeviceNotes - elif note.operatingsystem: + # elif note.operatingsystem: - note_item_model = note.operatingsystem - note_model = OperatingSystemNotes + # note_item_model = note.operatingsystem + # note_model = OperatingSystemNotes - elif note.service: + # elif note.service: - note_item_model = note.service - note_model = ServiceNotes + # note_item_model = note.service + # note_model = ServiceNotes - elif note.software: + # elif note.software: - note_item_model = note.software - note_model = SoftwareNotes + # note_item_model = note.software + # note_model = SoftwareNotes - note_model.objects.create( - organization = note.organization, - content = note.note, - content_type = ContentType.objects.get( - app_label = str(note_model._meta.app_label).lower(), - model = str(note_model.model.field.related_model.__name__).replace(' ', '').lower(), - ), - model = note_item_model, - created_by = note.usercreated, - modified_by = note.usermodified, - created = note.created, - modified = note.modified - ) + # note_model.objects.create( + # organization = note.organization, + # content = note.note, + # content_type = ContentType.objects.get( + # app_label = str(note_model._meta.app_label).lower(), + # model = str(note_model.model.field.related_model.__name__).replace(' ', '').lower(), + # ), + # model = note_item_model, + # created_by = note.usercreated, + # modified_by = note.usermodified, + # created = note.created, + # modified = note.modified + # ) diff --git a/app/core/migrations/0016_data_move_history_to_new_table.py b/app/core/migrations/0016_data_move_history_to_new_table.py index d957acae..cab7b26d 100644 --- a/app/core/migrations/0016_data_move_history_to_new_table.py +++ b/app/core/migrations/0016_data_move_history_to_new_table.py @@ -6,41 +6,41 @@ from django.conf import settings from django.contrib.auth.models import ContentType from django.db import migrations, models -from access.models.organization_history import Tenant, OrganizationHistory -from access.models.team_history import Team, TeamHistory +# from access.models.organization_history import Tenant, OrganizationHistory +# from access.models.team_history import Team, TeamHistory -from assistance.models.knowledge_base_history import KnowledgeBase, KnowledgeBaseHistory -from assistance.models.knowledge_base_category_history import KnowledgeBaseCategory, KnowledgeBaseCategoryHistory +# from assistance.models.knowledge_base_history import KnowledgeBase, KnowledgeBaseHistory +# from assistance.models.knowledge_base_category_history import KnowledgeBaseCategory, KnowledgeBaseCategoryHistory -from config_management.models.config_groups_history import ConfigGroups, ConfigGroupsHistory -from config_management.models.config_groups_hosts_history import ConfigGroupHosts, ConfigGroupHostsHistory -from config_management.models.config_groups_software_history import ConfigGroupSoftware, ConfigGroupSoftwareHistory +# from config_management.models.config_groups_history import ConfigGroups, ConfigGroupsHistory +# from config_management.models.config_groups_hosts_history import ConfigGroupHosts, ConfigGroupHostsHistory +# from config_management.models.config_groups_software_history import ConfigGroupSoftware, ConfigGroupSoftwareHistory -from core.models.history import History -from core.models.manufacturer_history import Manufacturer, ManufacturerHistory +# from core.models.history import History +# from core.models.manufacturer_history import Manufacturer, ManufacturerHistory -from itam.models.device_history import Device, DeviceHistory -from itam.models.device_model_history import DeviceModel, DeviceModelHistory -from itam.models.device_operating_system_history import DeviceOperatingSystem, DeviceOperatingSystemHistory -from itam.models.device_software_history import DeviceSoftware, DeviceSoftwareHistory -from itam.models.device_type_history import DeviceType, DeviceTypeHistory -from itam.models.operating_system_history import OperatingSystem, OperatingSystemHistory -from itam.models.operating_system_version_history import OperatingSystemVersion, OperatingSystemVersionHistory -from itam.models.software_history import Software, SoftwareHistory -from itam.models.software_category_history import SoftwareCategory, SoftwareCategoryHistory -from itam.models.software_version_history import SoftwareVersion, SoftwareVersionHistory +# from itam.models.device_history import Device, DeviceHistory +# from itam.models.device_model_history import DeviceModel, DeviceModelHistory +# from itam.models.device_operating_system_history import DeviceOperatingSystem, DeviceOperatingSystemHistory +# from itam.models.device_software_history import DeviceSoftware, DeviceSoftwareHistory +# from itam.models.device_type_history import DeviceType, DeviceTypeHistory +# from itam.models.operating_system_history import OperatingSystem, OperatingSystemHistory +# from itam.models.operating_system_version_history import OperatingSystemVersion, OperatingSystemVersionHistory +# from itam.models.software_history import Software, SoftwareHistory +# from itam.models.software_category_history import SoftwareCategory, SoftwareCategoryHistory +# from itam.models.software_version_history import SoftwareVersion, SoftwareVersionHistory -from itim.models.cluster_history import Cluster, ClusterHistory -from itim.models.cluster_type_history import ClusterType, ClusterTypeHistory -from itim.models.port_history import Port, PortHistory -from itim.models.service_history import Service, ServiceHistory +# from itim.models.cluster_history import Cluster, ClusterHistory +# from itim.models.cluster_type_history import ClusterType, ClusterTypeHistory +# from itim.models.port_history import Port, PortHistory +# from itim.models.service_history import Service, ServiceHistory -from project_management.models.project_history import Project, ProjectHistory -from project_management.models.project_milestone_history import ProjectMilestone, ProjectMilestoneHistory -from project_management.models.project_state_history import ProjectState, ProjectStateHistory -from project_management.models.project_type_history import ProjectType, ProjectTypeHistory +# from project_management.models.project_history import Project, ProjectHistory +# from project_management.models.project_milestone_history import ProjectMilestone, ProjectMilestoneHistory +# from project_management.models.project_state_history import ProjectState, ProjectStateHistory +# from project_management.models.project_type_history import ProjectType, ProjectTypeHistory -from settings.models.external_link_history import ExternalLink, ExternalLinkHistory +# from settings.models.external_link_history import ExternalLink, ExternalLinkHistory @@ -49,155 +49,155 @@ def move_history(apps, schema_editor): print('') print(f"migtating history data to new history tables.....") - model_history = History.objects.all().order_by('pk') # Select ALL and order by oldest first + # model_history = History.objects.all().order_by('pk') # Select ALL and order by oldest first - for old_entry in model_history: + # for old_entry in model_history: - print(f' Starting migration of pk-{str(old_entry.pk)}') + # print(f' Starting migration of pk-{str(old_entry.pk)}') - before = old_entry.before - after = old_entry.after + # before = old_entry.before + # after = old_entry.after - if( - type(before) is str - and before != '{}' - ): + # if( + # type(before) is str + # and before != '{}' + # ): - before = json.loads(before) + # before = json.loads(before) - elif before == '{}': + # elif before == '{}': - before:dict = {} + # before:dict = {} - if( - type(after) is str - and after != '{}' - ): + # if( + # type(after) is str + # and after != '{}' + # ): - after = json.loads(after) + # after = json.loads(after) - elif after == '{}': + # elif after == '{}': - after:dict = {} + # after:dict = {} - new_history_model = None + # new_history_model = None - item_details = model_details( - item_pk = old_entry.item_pk, - item_class = old_entry.item_class - ) + # item_details = model_details( + # item_pk = old_entry.item_pk, + # item_class = old_entry.item_class + # ) - new_history_model = item_details['class'] + # new_history_model = item_details['class'] - if item_details['object'] is not None: + # if item_details['object'] is not None: - match item_details['object']._meta.model_name: + # match item_details['object']._meta.model_name: - case 'configgroups': + # case 'configgroups': - if old_entry.item_class == old_entry.item_parent_class: + # if old_entry.item_class == old_entry.item_parent_class: - old_entry.item_parent_pk = None - old_entry.item_parent_class = None + # old_entry.item_parent_pk = None + # old_entry.item_parent_class = None - case 'configgroupsoftware': + # case 'configgroupsoftware': - old_entry.item_parent_pk = item_details['object'].config_group.pk + # old_entry.item_parent_pk = item_details['object'].config_group.pk - old_entry.item_parent_class = item_details['object'].config_group._meta.model_name + # old_entry.item_parent_class = item_details['object'].config_group._meta.model_name - case 'operatingsystemversion': + # case 'operatingsystemversion': - old_entry.item_parent_pk = None - old_entry.item_parent_class = None + # old_entry.item_parent_pk = None + # old_entry.item_parent_class = None - case 'softwareversion': + # case 'softwareversion': - old_entry.item_parent_pk = None - old_entry.item_parent_class = None + # old_entry.item_parent_pk = None + # old_entry.item_parent_class = None - case 'projectmilestone': + # case 'projectmilestone': - old_entry.item_parent_pk = None - old_entry.item_parent_class = None + # old_entry.item_parent_pk = None + # old_entry.item_parent_class = None - item_details_parent = None - if( - old_entry.item_parent_pk - and item_details['class'] is not None - and item_details['content'] is not None - and item_details['object'] is not None - and new_history_model._meta.model_name != 'team' - and new_history_model._meta.model_name != 'teamhistory' - ): + # item_details_parent = None + # if( + # old_entry.item_parent_pk + # and item_details['class'] is not None + # and item_details['content'] is not None + # and item_details['object'] is not None + # and new_history_model._meta.model_name != 'team' + # and new_history_model._meta.model_name != 'teamhistory' + # ): - item_details_parent = model_details( - item_pk = old_entry.item_parent_pk, - item_class = old_entry.item_parent_class - ) + # item_details_parent = model_details( + # item_pk = old_entry.item_parent_pk, + # item_class = old_entry.item_parent_class + # ) - new_entry = None - if item_details_parent is not None: + # new_entry = None + # if item_details_parent is not None: - new_entry = new_history_model.objects.create( - organization = item_details_parent['object'].organization, - before = before, - after = after, - action = old_entry.action, - user = old_entry.user, - created = old_entry.created, + # new_entry = new_history_model.objects.create( + # organization = item_details_parent['object'].organization, + # before = before, + # after = after, + # action = old_entry.action, + # user = old_entry.user, + # created = old_entry.created, - content_type = item_details_parent['content'], - model = item_details_parent['object'], - child_model = item_details['object'], - ) + # content_type = item_details_parent['content'], + # model = item_details_parent['object'], + # child_model = item_details['object'], + # ) - elif( - item_details['class'] is not None - and item_details['content'] is not None - and item_details['object'] is not None - ): + # elif( + # item_details['class'] is not None + # and item_details['content'] is not None + # and item_details['object'] is not None + # ): - organization = getattr(item_details['object'], 'organization', None) + # organization = getattr(item_details['object'], 'organization', None) - if item_details['object']._meta.model_name == 'organization': + # if item_details['object']._meta.model_name == 'organization': - organization = item_details['object'] + # organization = item_details['object'] - new_entry = new_history_model.objects.create( - organization = organization, - before = before, - after = after, - action = old_entry.action, - user = old_entry.user, - created = old_entry.created, + # new_entry = new_history_model.objects.create( + # organization = organization, + # before = before, + # after = after, + # action = old_entry.action, + # user = old_entry.user, + # created = old_entry.created, - content_type = item_details['content'], - model = item_details['object'], - ) + # content_type = item_details['content'], + # model = item_details['object'], + # ) - else: + # else: - print(f' [Notice] Could not determine details, pk-{str(old_entry.pk)} not migrated') + # print(f' [Notice] Could not determine details, pk-{str(old_entry.pk)} not migrated') - if new_entry is None: + # if new_entry is None: - print(f' [Failure] not migrated, pk-{str(old_entry.pk)}') + # print(f' [Failure] not migrated, pk-{str(old_entry.pk)}') - elif new_entry is not None: + # elif new_entry is not None: - print(f' [Success] migrated history entry pk-{str(old_entry.pk)} to new history table pk{str(new_entry.pk)}') + # print(f' [Success] migrated history entry pk-{str(old_entry.pk)} to new history table pk{str(new_entry.pk)}') @@ -220,210 +220,210 @@ class Migration(migrations.Migration): -def model_details(item_pk, item_class) -> dict: +# def model_details(item_pk, item_class) -> dict: - history_object = None - history_class = None - history_content = None +# history_object = None +# history_class = None +# history_content = None - model_class = None +# model_class = None - match item_class: +# match item_class: - case 'appsettings': +# case 'appsettings': - pass +# pass - case 'cluster': +# case 'cluster': - model_class = Cluster +# model_class = Cluster - history_class = ClusterHistory +# history_class = ClusterHistory - case 'clustertype': +# case 'clustertype': - model_class = ClusterType +# model_class = ClusterType - history_class = ClusterTypeHistory +# history_class = ClusterTypeHistory - case 'configgrouphosts': +# case 'configgrouphosts': - model_class = ConfigGroupHosts +# model_class = ConfigGroupHosts - history_class = ConfigGroupHostsHistory +# history_class = ConfigGroupHostsHistory - case 'configgroups': +# case 'configgroups': - model_class = ConfigGroups +# model_class = ConfigGroups - history_class = ConfigGroupsHistory +# history_class = ConfigGroupsHistory - case 'configgroupsoftware': +# case 'configgroupsoftware': - model_class = ConfigGroupSoftware +# model_class = ConfigGroupSoftware - history_class = ConfigGroupSoftwareHistory +# history_class = ConfigGroupSoftwareHistory - case 'device': +# case 'device': - model_class = Device +# model_class = Device - history_class = DeviceHistory +# history_class = DeviceHistory - case 'devicemodel': +# case 'devicemodel': - model_class = DeviceModel +# model_class = DeviceModel - history_class = DeviceModelHistory +# history_class = DeviceModelHistory - case 'deviceoperatingsystem': +# case 'deviceoperatingsystem': - model_class = DeviceOperatingSystem +# model_class = DeviceOperatingSystem - history_class = DeviceOperatingSystemHistory +# history_class = DeviceOperatingSystemHistory - case 'devicesoftware': +# case 'devicesoftware': - model_class = DeviceSoftware +# model_class = DeviceSoftware - history_class = DeviceSoftwareHistory +# history_class = DeviceSoftwareHistory - case 'devicetype': +# case 'devicetype': - model_class = DeviceType +# model_class = DeviceType - history_class = DeviceTypeHistory +# history_class = DeviceTypeHistory - case 'externallink': +# case 'externallink': - model_class = ExternalLink +# model_class = ExternalLink - history_class = ExternalLinkHistory +# history_class = ExternalLinkHistory - case 'knowledgebase': +# case 'knowledgebase': - model_class = KnowledgeBase +# model_class = KnowledgeBase - history_class = KnowledgeBaseHistory +# history_class = KnowledgeBaseHistory - case 'knowledgebasecategory': +# case 'knowledgebasecategory': - model_class = KnowledgeBaseCategory +# model_class = KnowledgeBaseCategory - history_class = KnowledgeBaseCategoryHistory +# history_class = KnowledgeBaseCategoryHistory - case 'manufacturer': +# case 'manufacturer': - model_class = Manufacturer +# model_class = Manufacturer - history_class = ManufacturerHistory +# history_class = ManufacturerHistory - case 'operatingsystem': +# case 'operatingsystem': - model_class = OperatingSystem +# model_class = OperatingSystem - history_class = OperatingSystemHistory +# history_class = OperatingSystemHistory - case 'operatingsystemversion': +# case 'operatingsystemversion': - model_class = OperatingSystemVersion +# model_class = OperatingSystemVersion - history_class = OperatingSystemVersionHistory +# history_class = OperatingSystemVersionHistory - case 'organization': +# case 'organization': - model_class = Tenant +# model_class = Tenant - history_class = OrganizationHistory +# history_class = OrganizationHistory - case 'port': +# case 'port': - model_class = Port +# model_class = Port - history_class = PortHistory +# history_class = PortHistory - case 'project': +# case 'project': - model_class = Project +# model_class = Project - history_class = ProjectHistory +# history_class = ProjectHistory - case 'projectmilestone': +# case 'projectmilestone': - model_class = ProjectMilestone +# model_class = ProjectMilestone - history_class = ProjectMilestoneHistory +# history_class = ProjectMilestoneHistory - case 'projectstate': +# case 'projectstate': - model_class = ProjectState +# model_class = ProjectState - history_class = ProjectStateHistory +# history_class = ProjectStateHistory - case 'projecttype': +# case 'projecttype': - model_class = ProjectType +# model_class = ProjectType - history_class = ProjectTypeHistory +# history_class = ProjectTypeHistory - case 'service': +# case 'service': - model_class = Service +# model_class = Service - history_class = ServiceHistory +# history_class = ServiceHistory - case 'software': +# case 'software': - model_class = Software +# model_class = Software - history_class = SoftwareHistory +# history_class = SoftwareHistory - case 'softwarecategory': +# case 'softwarecategory': - model_class = SoftwareCategory +# model_class = SoftwareCategory - history_class = SoftwareCategoryHistory +# history_class = SoftwareCategoryHistory - case 'softwareversion': +# case 'softwareversion': - model_class = SoftwareVersion +# model_class = SoftwareVersion - history_class = SoftwareVersionHistory +# history_class = SoftwareVersionHistory - case 'team': +# case 'team': - model_class = Team +# model_class = Team - history_class = TeamHistory +# history_class = TeamHistory - if( - model_class is not None - and history_class is not None - ): +# if( +# model_class is not None +# and history_class is not None +# ): - try: +# try: - if history_object is None: +# if history_object is None: - history_object = model_class.objects.get( - pk = item_pk - ) +# history_object = model_class.objects.get( +# pk = item_pk +# ) - history_content = ContentType.objects.get( - app_label = model_class._meta.app_label, - model = model_class._meta.model_name, - ) +# history_content = ContentType.objects.get( +# app_label = model_class._meta.app_label, +# model = model_class._meta.model_name, +# ) - except model_class.DoesNotExist: +# except model_class.DoesNotExist: - print(f' model {model_class._meta.model_name}-{str(item_pk)} does not exist') +# print(f' model {model_class._meta.model_name}-{str(item_pk)} does not exist') - return { - 'class': history_class, - 'content': history_content, - 'object': history_object, - } +# return { +# 'class': history_class, +# 'content': history_content, +# 'object': history_object, +# }