Skip to content

Commit

Permalink
postgresql: Add schema v4.6 with more indexes
Browse files Browse the repository at this point in the history
Add PostgreSQL schema v4.6 adding more indexes to help Grafana
dashboards.
  • Loading branch information
spbnick committed Mar 12, 2024
1 parent 79875d6 commit 4007930
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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_05 import Schema as LatestSchema
from kcidb.db.postgresql.v04_06 import Schema as LatestSchema


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

from kcidb.misc import merge_dicts
from kcidb.db.postgresql.schema import Index
from .v04_05 import Schema as PreviousSchema


# It's OK, pylint: disable=too-many-ancestors
class Schema(PreviousSchema):
"""PostgreSQL database schema v4.6"""

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

# A map of index names and schemas
INDEXES = merge_dicts(PreviousSchema.INDEXES, dict(
checkouts_valid=Index("checkouts", ["valid"]),
builds_compiler=Index("builds", ["compiler"]),
builds_valid=Index("builds", ["valid"]),
tests_waived=Index("tests", ["waived"]),
))

@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

0 comments on commit 4007930

Please sign in to comment.