Skip to content

Commit

Permalink
Use old session management for icat_db_generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
louise-davies committed Feb 4, 2021
1 parent 582817a commit 9e8bed2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion datagateway_api/src/api_start_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_app_infrastructure(flask_app):

if backend_type == "db":
flask_app.config["SQLALCHEMY_DATABASE_URI"] = Constants.DATABASE_URL
flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(flask_app)

initialise_spec(spec)
Expand Down
12 changes: 10 additions & 2 deletions util/icat_db_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
from random import choice, randrange, seed

from faker import Faker
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.pool import QueuePool

from datagateway_api.common.constants import Constants
from datagateway_api.common.database import models
from datagateway_api.common.database.helpers import db

parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -33,7 +36,12 @@
faker.seed(SEED)
seed(a=SEED)

session = db.session

engine = create_engine(
Constants.DATABASE_URL, poolclass=QueuePool, pool_size=100, max_overflow=0,
)
session_factory = sessionmaker(engine)
session = scoped_session(session_factory)()


def post_entity(entity):
Expand Down

0 comments on commit 9e8bed2

Please sign in to comment.