Skip to content

Instantly share code, notes, and snippets.

@dario61081
Last active December 24, 2023 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dario61081/6ae953b6d5d15a100d50b57c270e41b1 to your computer and use it in GitHub Desktop.
Save dario61081/6ae953b6d5d15a100d50b57c270e41b1 to your computer and use it in GitHub Desktop.
Funciones para verificar integridad de datos
# @app.before_first_request
# def before_first_request():
# logger.debug("Verificando modelos")
# models = ModelBase.__subclasses__()
# logger.debug(f"modelos encontrados: {models}")
# check_models_requirements(models)
# def check_models_requirements(models):
# """Check if the models are created in the database, if not, create them."""
# with repo() as db:
# transaction = db.get_session().begin()
# try:
# for mdl in models:
# logger.debug(f"checking model {mdl.__tablename__}")
# if not db.table_exists(mdl):
# db.create_table(mdl)
# logger.debug(f"(OK) created table {mdl.__tablename__}")
# else:
# logger.debug(f"(OK) table {mdl.__tablename__} exists")
# except Exception as ex:
# transaction.rollback()
# logger.error(f"error checking models {ex}")
# else:
# transaction.commit()
# logger.success("models checked successfully")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment