Skip to content

Commit 58aa951

Browse files
committed
This includes more change than it should, because I'd originally segregated the database files into a `db` directory while Nikhil went with `database`.
1 parent 18cdc73 commit 58aa951

File tree

18 files changed

+28
-95
lines changed

18 files changed

+28
-95
lines changed

lib/pbench/cli/server/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pbench.common.exceptions import BadConfig, ConfigFileNotSpecified
1010
from pbench.server.api import create_app, get_server_config
11-
from pbench.server.db.database import Database
11+
from pbench.server.database.database import Database
1212
from pbench.common.logger import get_pbench_logger
1313

1414

lib/pbench/server/api/resources/upload_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from flask import request, jsonify
1010
from werkzeug.utils import secure_filename
1111
from pbench.server.utils import filesize_bytes
12-
from pbench.server.db.models.tracker import Dataset, States
12+
from pbench.server.database.models.tracker import Dataset, States
1313

1414

1515
ALLOWED_EXTENSIONS = {"xz"}

lib/pbench/server/api/resources/users_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ def post(self):
9292

9393
first_name = user_data.get("first_name")
9494
if not first_name:
95-
self.logger.warning("Missing firstName field")
96-
abort(400, message="Missing firstName field")
95+
self.logger.warning("Missing first_name field")
96+
abort(400, message="Missing first_name field")
9797

9898
last_name = user_data.get("last_name")
9999
if not last_name:
100-
self.logger.warning("Missing lastName field")
101-
abort(400, message="Missing lastName field")
100+
self.logger.warning("Missing last_name field")
101+
abort(400, message="Missing last_name field")
102102

103103
try:
104104
user = User(
@@ -325,8 +325,8 @@ def get(self, username):
325325
"message": "Success"/"failure message",
326326
"data": {
327327
"username": <username>,
328-
"firstName": <firstName>,
329-
"lastName": <lastName>,
328+
"first_name": <firstName>,
329+
"last_name": <lastName>,
330330
"registered_on": registered_on,
331331
}
332332
}

lib/pbench/server/database/database.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@ def get_engine_uri(config, logger):
2121
)
2222
return None
2323

24-
# return f"postgresql+{psql_driver}://{psql_username}:{psql_password}@{psql_host}:{psql_port}/{psql_db}"
25-
26-
@staticmethod
27-
def init_engine(server_config, logger):
28-
try:
29-
return create_engine(Database.get_engine_uri(server_config, logger))
30-
except Exception:
31-
logger.exception("Exception while creating a sqlalchemy engine")
32-
return None
33-
3424
@staticmethod
3525
def init_db(server_config, logger):
26+
# Attach the logger to the base class for models to find
27+
if not hasattr(Database.Base, "logger"):
28+
Database.Base.logger = logger
29+
3630
# Make sure all the models are imported before this function gets called
3731
# so that they will be registered properly on the metadata. Otherwise
3832
# metadata will not have any tables and create_all functionality will do nothing
3933

4034
Database.Base.query = Database.db_session.query_property()
41-
35+
Database.db_session.remove() # Remove the placeholder static session
4236
engine = create_engine(Database.get_engine_uri(server_config, logger))
4337
Database.Base.metadata.create_all(bind=engine)
4438
Database.db_session.configure(bind=engine)

lib/pbench/server/db/models/tracker.py renamed to lib/pbench/server/database/models/tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sqlalchemy.orm import relationship, validates
1717
from sqlalchemy.exc import SQLAlchemyError
1818

19-
from pbench.server.db.database import Database
19+
from pbench.server.database.database import Database
2020

2121

2222
class DatasetError(Exception):

lib/pbench/server/db/__init__.py

Whitespace-only changes.

lib/pbench/server/db/database.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

lib/pbench/server/db/models/__init__.py

Whitespace-only changes.

lib/pbench/server/indexing_tarballs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
es_index,
2222
VERSION,
2323
)
24-
from pbench.server.db.models.tracker import (
24+
from pbench.server.database.models.tracker import (
2525
Dataset,
2626
States,
2727
Metadata,

lib/pbench/server/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import shutil
44

5-
from pbench.server.db.models.tracker import Dataset, States, DatasetNotFound
5+
from pbench.server.database.models.tracker import Dataset, States, DatasetNotFound
66

77

88
def rename_tb_link(tb, dest, logger):

0 commit comments

Comments
 (0)