Fixing broken document migration
* adds changes to document migration to correctly migrate documents
This commit is contained in:
parent
c7c6eef2e5
commit
022e4a580b
@ -90,18 +90,22 @@ class BaseMigrater:
|
||||
doc_comment = doc_result[1]
|
||||
doc_date = doc_result[2]
|
||||
try:
|
||||
with open(doc_path, encoding="latin1") as file:
|
||||
with open(doc_path, "rb") as file:
|
||||
file = UploadedFile(file)
|
||||
doc_title = "Migrierte Datei"
|
||||
doc_date = doc_date or "1970-01-01"
|
||||
doc_exists = document_cls.objects.filter(
|
||||
instance=instance,
|
||||
title=doc_title,
|
||||
comment=doc_comment,
|
||||
date_of_creation=doc_date
|
||||
).exists()
|
||||
if doc_exists:
|
||||
continue
|
||||
|
||||
doc_file = self.__find_migrated_file_recursive(
|
||||
document_cls,
|
||||
instance,
|
||||
file.name
|
||||
)
|
||||
|
||||
if doc_file is not None:
|
||||
doc_file.delete()
|
||||
else:
|
||||
print(f"------ Could not find file, that should have been migrated already. Adding new version anyway: {doc_path}")
|
||||
|
||||
doc = document_cls.objects.create(
|
||||
title=doc_title,
|
||||
comment=doc_comment,
|
||||
@ -114,6 +118,21 @@ class BaseMigrater:
|
||||
tmp_cursor.close()
|
||||
return instance
|
||||
|
||||
def __find_migrated_file_recursive(self, document_cls, instance, file_name):
|
||||
file_name_tmp = file_name
|
||||
try:
|
||||
doc_file = document_cls.objects.get(
|
||||
instance=instance,
|
||||
file__icontains=file_name_tmp
|
||||
)
|
||||
return doc_file
|
||||
except ObjectDoesNotExist:
|
||||
file_name_tmp = file_name_tmp[:len(file_name_tmp) - 1]
|
||||
if len(file_name_tmp) > 0:
|
||||
return self.__find_migrated_file_recursive(document_cls, instance, file_name_tmp)
|
||||
else:
|
||||
return None
|
||||
|
||||
def _migrate_log(self, instance, db_result: tuple):
|
||||
identifier = f"'{db_result[0]}'"
|
||||
tmp_cursor = self.db_connection.cursor()
|
||||
|
@ -146,6 +146,7 @@ class InterventionMigrater(BaseMigrater):
|
||||
|
||||
def migrate(self):
|
||||
self.connect_db()
|
||||
el = "'EIV-1380625802430'"
|
||||
cursor = self.db_connection.cursor()
|
||||
cursor.execute(
|
||||
'select '
|
||||
@ -180,7 +181,8 @@ class InterventionMigrater(BaseMigrater):
|
||||
'where '
|
||||
'om."OKL"=7730085 and '
|
||||
'om.archiv=false and '
|
||||
'om.nicht_vollstaendig=0 '
|
||||
'om.nicht_vollstaendig=0 and '
|
||||
f'om."KENNUNG"={el}'
|
||||
)
|
||||
|
||||
all_eivs = cursor.fetchall()
|
||||
@ -196,17 +198,17 @@ class InterventionMigrater(BaseMigrater):
|
||||
intervention = Intervention.objects.get_or_create(
|
||||
identifier=eiv[0]
|
||||
)[0]
|
||||
intervention.title = eiv[1]
|
||||
intervention.comment = eiv_comment
|
||||
intervention = self._migrate_intervention_legal(intervention, eiv)
|
||||
intervention = self._migrate_intervention_responsibility(intervention, eiv)
|
||||
#intervention.title = eiv[1]
|
||||
#intervention.comment = eiv_comment
|
||||
#intervention = self._migrate_intervention_legal(intervention, eiv)
|
||||
#intervention = self._migrate_intervention_responsibility(intervention, eiv)
|
||||
intervention = self._migrate_documents(intervention, InterventionDocument, eiv)
|
||||
intervention = self._migrate_log(intervention, eiv)
|
||||
intervention = self._migrate_revocation(intervention, eiv)
|
||||
#intervention = self._migrate_log(intervention, eiv)
|
||||
#intervention = self._migrate_revocation(intervention, eiv)
|
||||
intervention.save()
|
||||
|
||||
intervention = self._migrate_geometry(intervention, eiv)
|
||||
intervention = self._migrate_intervention_payment(intervention, eiv)
|
||||
#intervention = self._migrate_geometry(intervention, eiv)
|
||||
#intervention = self._migrate_intervention_payment(intervention, eiv)
|
||||
intervention.save()
|
||||
|
||||
num_processed += 1
|
||||
|
@ -20,11 +20,11 @@ class Command(BaseKonovaCommand):
|
||||
try:
|
||||
migraters = [
|
||||
InterventionMigrater(options),
|
||||
CompensationMigrater(options),
|
||||
EmaMigrater(options),
|
||||
EcoAccountMigrater(options),
|
||||
InterventionRecordedMigrater(options),
|
||||
UserMigrater(options),
|
||||
#CompensationMigrater(options),
|
||||
#EmaMigrater(options),
|
||||
#EcoAccountMigrater(options),
|
||||
#InterventionRecordedMigrater(options),
|
||||
#UserMigrater(options),
|
||||
]
|
||||
for migrater in migraters:
|
||||
migrater.migrate()
|
||||
|
Loading…
Reference in New Issue
Block a user