From 7478160094f7f55304fc3d67fe177e04a7eba556 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 15 Aug 2021 09:33:18 +0200 Subject: [PATCH] Clear caches after migration --- tools/import_scodoc7_dept.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/import_scodoc7_dept.py b/tools/import_scodoc7_dept.py index 23f2b9fd37..5cfd6524d3 100644 --- a/tools/import_scodoc7_dept.py +++ b/tools/import_scodoc7_dept.py @@ -13,6 +13,7 @@ from flask import current_app from app import db from app.auth.models import User, get_super_admin import app +from app import clear_scodoc_cache from app import models from app.scodoc import notesdb as ndb @@ -96,7 +97,7 @@ def import_scodoc7_dept(dept_id: str, dept_db_uri=None): if dept_db_uri is None: dept_db_uri = f"postgresql:///SCO{dept_id}" setup_log(dept_id) - current_app.logger.info(f"connecting to database {dept_db_uri}") + logging.info(f"connecting to database {dept_db_uri}") cnx = psycopg2.connect(dept_db_uri) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) # Create dept: @@ -109,10 +110,13 @@ def import_scodoc7_dept(dept_id: str, dept_db_uri=None): default_user = get_super_admin() # for (table, id_name) in SCO7_TABLES_ORDONNEES: - current_app.logger.info(f"{dept.acronym}: converting {table}...") + logging.info(f"{dept.acronym}: converting {table}...") klass = get_class_for_table(table) n = convert_table(dept, cursor, id_from_scodoc7, klass, id_name, default_user) - current_app.logger.info(f" inserted {n} objects.") + logging.info(f" inserted {n} objects.") + logging.info(f"All table imported: clearing app caches...") + clear_scodoc_cache() + logging.info(f"Done.") def get_class_for_table(table): @@ -301,7 +305,7 @@ def convert_object( uid = login2id.get(login_scodoc7) if not uid: uid = default_user.id - current_app.logger.warning( + logging.warning( f"non existent user: {login_scodoc7}: giving {table_name}({old_id}) to admin" ) # raise ValueError(f"non existent user: {login_scodoc7}")