From 3d2b6d9a0c1b83c57effe105311057dbdfc83b7d Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Mon, 29 Jan 2024 13:39:57 +0200 Subject: [PATCH 1/2] misc: Add timestamps to command-line logs only --- kcidb/misc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kcidb/misc.py b/kcidb/misc.py index b0fab1c5..d9473624 100644 --- a/kcidb/misc.py +++ b/kcidb/misc.py @@ -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"]) @@ -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 From 767bee28b05f8f07fee43d19eaf6279aed952109 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Mon, 29 Jan 2024 14:47:53 +0200 Subject: [PATCH 2/2] postgresql: Sprinkle indexes in new schema v4.4 --- kcidb/db/postgresql/__init__.py | 2 +- kcidb/db/postgresql/v04_04.py | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 kcidb/db/postgresql/v04_04.py diff --git a/kcidb/db/postgresql/__init__.py b/kcidb/db/postgresql/__init__.py index 5f17cf49..f45f9eec 100644 --- a/kcidb/db/postgresql/__init__.py +++ b/kcidb/db/postgresql/__init__.py @@ -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): diff --git a/kcidb/db/postgresql/v04_04.py b/kcidb/db/postgresql/v04_04.py new file mode 100644 index 00000000..27c280a5 --- /dev/null +++ b/kcidb/db/postgresql/v04_04.py @@ -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