from flask import Flask
from flask_sqlalchemy import SQLAlchemy

from server import config

cnf = config.get_app_config()

app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = (
    cnf.db_uri.replace("+asyncpg", "") + "?options=-c%20search_path=" + str(cnf.db_search_path)
)
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {
    "pool_recycle": 600,
    "pool_pre_ping": True,
    "pool_size": 30,
}
app.config["SECRET_KEY"] = cnf.admin_secret_key
app.config["SQLALCHEMY_ECHO"] = True
db_sync = SQLAlchemy(app)
