TG-35 : Test de la connexion à la BDD
This commit is contained in:
parent
c8d8d2f47e
commit
bd9110b0fb
@ -22,6 +22,7 @@ class Prod(Config):
|
||||
class Debug(Config):
|
||||
DEBUG = True
|
||||
SESSION_COOKIE_SECURE = False
|
||||
SQLALCHEMY_DATABASE_URI = 'mysql://ola:ola@localhost/OLA'
|
||||
|
||||
|
||||
class Test(Config):
|
||||
|
@ -1,10 +1,11 @@
|
||||
import importlib
|
||||
from datetime import timedelta
|
||||
|
||||
from flask import Flask, session
|
||||
from flask_restful import Api
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
import importlib
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
|
||||
|
||||
def configure_app(config="prod"):
|
||||
@ -32,6 +33,9 @@ configure_app()
|
||||
|
||||
# SQLAlchemy
|
||||
db = SQLAlchemy(app)
|
||||
Base = automap_base()
|
||||
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])
|
||||
Base.prepare(engine, reflect=True)
|
||||
|
||||
# RestFul Flask
|
||||
api = Api(app)
|
||||
|
9
backend/app/model.py
Normal file
9
backend/app/model.py
Normal file
@ -0,0 +1,9 @@
|
||||
from backend.app.core import Base
|
||||
|
||||
USER = Base.classes.user
|
||||
SETTINGS = Base.classes.settings
|
||||
HASHTABLE = Base.classes.hashtable
|
||||
GROUP = Base.classes.group
|
||||
GROUP_CONTENT = Base.classes.group_content
|
||||
PERIOD = Base.classes.period
|
||||
LIVRET = Base.classes.livret
|
@ -1,15 +1,13 @@
|
||||
import argparse
|
||||
import importlib
|
||||
import os
|
||||
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from flask_migrate import Migrate, MigrateCommand
|
||||
from flask_script import Manager, Command
|
||||
from flask_script import prompt_bool
|
||||
|
||||
from backend.app.core import app, db, configure_app
|
||||
|
||||
from backend.app.core import configure_app
|
||||
|
||||
warnings.simplefilter('ignore')
|
||||
|
||||
@ -24,16 +22,15 @@ if args.debug:
|
||||
if args.test:
|
||||
configure_app(config="test")
|
||||
|
||||
migrate = Migrate(app, db)
|
||||
db = importlib.import_module("db", "backend.app.core")
|
||||
app = importlib.import_module("app", "backend.app.core")
|
||||
|
||||
manager = Manager(app)
|
||||
manager.add_option("-d", "--debug",
|
||||
action="store_true", dest="debug", required=False)
|
||||
manager.add_option("-t", "--test",
|
||||
action="store_true", dest="test", required=False)
|
||||
|
||||
# migrations : python manage.py db to show usage
|
||||
manager.add_command('db', MigrateCommand)
|
||||
|
||||
|
||||
class SeedDB(Command):
|
||||
"""Seed the db """
|
||||
@ -56,6 +53,17 @@ class DropDB(Command):
|
||||
manager.add_command('dropdb', DropDB())
|
||||
|
||||
|
||||
class CheckDB(Command):
|
||||
"""Print database structure"""
|
||||
|
||||
def run(self):
|
||||
print("List of parsed tables:")
|
||||
print(db.metadata.tables.keys())
|
||||
|
||||
|
||||
manager.add_command('checkdb', CheckDB())
|
||||
|
||||
|
||||
class RunTests(Command):
|
||||
"""Seed the db """
|
||||
def run(self):
|
||||
|
@ -4,4 +4,5 @@ flask-sqlalchemy < 2.2
|
||||
flask-migrate < 2.1
|
||||
flask-bootstrap < 3.4
|
||||
flask-restful < 0.4
|
||||
passlib < 1.8
|
||||
passlib < 1.8
|
||||
mysqlclient < 1.4
|
Reference in New Issue
Block a user