1
0
forked from ScoDoc/ScoDoc

Clear caches after migration

This commit is contained in:
Emmanuel Viennet 2021-08-15 09:33:18 +02:00
parent 3049545796
commit 7478160094

View File

@ -13,6 +13,7 @@ from flask import current_app
from app import db from app import db
from app.auth.models import User, get_super_admin from app.auth.models import User, get_super_admin
import app import app
from app import clear_scodoc_cache
from app import models from app import models
from app.scodoc import notesdb as ndb 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: if dept_db_uri is None:
dept_db_uri = f"postgresql:///SCO{dept_id}" dept_db_uri = f"postgresql:///SCO{dept_id}"
setup_log(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) cnx = psycopg2.connect(dept_db_uri)
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
# Create dept: # Create dept:
@ -109,10 +110,13 @@ def import_scodoc7_dept(dept_id: str, dept_db_uri=None):
default_user = get_super_admin() default_user = get_super_admin()
# #
for (table, id_name) in SCO7_TABLES_ORDONNEES: 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) klass = get_class_for_table(table)
n = convert_table(dept, cursor, id_from_scodoc7, klass, id_name, default_user) 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): def get_class_for_table(table):
@ -301,7 +305,7 @@ def convert_object(
uid = login2id.get(login_scodoc7) uid = login2id.get(login_scodoc7)
if not uid: if not uid:
uid = default_user.id uid = default_user.id
current_app.logger.warning( logging.warning(
f"non existent user: {login_scodoc7}: giving {table_name}({old_id}) to admin" f"non existent user: {login_scodoc7}: giving {table_name}({old_id}) to admin"
) )
# raise ValueError(f"non existent user: {login_scodoc7}") # raise ValueError(f"non existent user: {login_scodoc7}")