Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprinkle indexes on PostgreSQL #498

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kcidb/db/postgresql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import textwrap
from kcidb.db.schematic import Driver as SchematicDriver
from kcidb.db.postgresql.v04_03 import Schema as LatestSchema
from kcidb.db.postgresql.v04_04 import Schema as LatestSchema


class Driver(SchematicDriver):
Expand Down
43 changes: 43 additions & 0 deletions kcidb/db/postgresql/v04_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Kernel CI report database - PostgreSQL schema v4.4"""

from kcidb.db.postgresql.schema import Index
from .v04_03 import Schema as PreviousSchema


class Schema(PreviousSchema):
"""PostgreSQL database schema v4.4"""

# The schema's version.
version = (4, 4)

# A map of index names and schemas
INDEXES = dict(
checkouts_git_commit_hash_patchset_hash=Index(
"checkouts", ["git_commit_hash", "patchset_hash"]
),
builds_checkout_id=Index("builds", ["checkout_id"]),
tests_build_id=Index("tests", ["build_id"]),
incidents_build_id=Index("incidents", ["build_id"]),
incidents_test_id=Index("incidents", ["test_id"]),
incidents_issue_id=Index("incidents", ["issue_id"]),
)

@classmethod
def _inherit(cls, conn):
"""
Inerit the database data from the previous schema version (if any).

Args:
conn: Connection to the database to inherit. The database must
comply with the previous version of the schema.
"""
assert isinstance(conn, cls.Connection)
with conn, conn.cursor() as cursor:
for index_name, index_schema in cls.INDEXES.items():
if index_name not in PreviousSchema.INDEXES:
try:
cursor.execute(index_schema.format_create(index_name))
except Exception as exc:
raise Exception(
f"Failed creating index {index_name!r}"
) from exc
8 changes: 4 additions & 4 deletions kcidb/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ def logging_setup(level):
"""
assert isinstance(level, int)
logging.getLogger().setLevel(level)
# Add timestamps to log messages
for handler in logging.getLogger().handlers:
handler.setFormatter(logging.Formatter(
'%(asctime)s:%(levelname)s:%(name)s:%(message)s'))
# TODO Consider separate arguments for controlling the below
logging.getLogger("urllib3").setLevel(LOGGING_LEVEL_MAP["NONE"])
logging.getLogger("google").setLevel(LOGGING_LEVEL_MAP["NONE"])
Expand Down Expand Up @@ -149,6 +145,10 @@ def parse_args(self, args=None, namespace=None):
args = super().parse_args(args=args, namespace=namespace)
logging.basicConfig()
logging_setup(LOGGING_LEVEL_MAP[args.log_level])
# Add timestamps to log messages
for handler in logging.getLogger().handlers:
handler.setFormatter(logging.Formatter(
'%(asctime)s:%(levelname)s:%(name)s:%(message)s'))
return args


Expand Down
Loading