Blame view

app/commands/lesia_db.py 1.1 KB
14f36f55   hitier   Move lesia init c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import sys

from flask import current_app
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session

lesia_base = automap_base()

engine = create_engine(current_app.config['LESIA_AGENTS_DB_URI'])

# reflect the tables
try:
    lesia_base.prepare(engine, reflect=True)
b7839ec6   hitier   Show db connexion...
16
17
except OperationalError as oe:
    current_app.logger.error(oe)
14f36f55   hitier   Move lesia init c...
18
19
20
21
22
    current_app.logger.error("Please, configure the mysql database (see db_config.py)")
    sys.exit(-1)

lesia_session = Session(engine)

14f36f55   hitier   Move lesia init c...
23
24
25
26
27
28
29
30
# mapped classes are now created with names by default
# matching that of the table name.
lesia_agent = lesia_base.classes.agent
lesia_service = lesia_base.classes.gestit_services
lesia_project = lesia_base.classes.gestit_projets
lesia_fonction = lesia_base.classes.gestit_fonctions
lesia_affectation = lesia_base.classes.gestit_affectations
lesia_periods = lesia_base.classes.gestit_semestres
90fdccc7   hitier   Now feed projects...
31
32
33
lesia_domains = lesia_base.classes.gestit_domaines
lesia_poles = lesia_base.classes.poles
lesia_domainprojects = lesia_base.classes.gestit_domaine_projets