Skip to content

Commit

Permalink
schema: Describe object ID fields
Browse files Browse the repository at this point in the history
Support describing ID fields of objects accepted by schemas.
Describe the issues introduced in v4.1 as having only one ID field to
allow KCIDB transition to multi-value IDs. The "version" field will be
added to issue's IDs in a following commit, once KCIDB is ready.
  • Loading branch information
spbnick committed Oct 11, 2024
1 parent 9142220 commit 98f516f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kcidb_io/schema/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def __init__(cls, name, bases, _dict, **kwargs):
all(isinstance(e, str) for e in v)
for k, v in cls.graph.items())
assert "" in cls.graph
assert isinstance(cls.id_fields, dict)
assert set(cls.graph) - {""} == set(cls.id_fields)
assert all(isinstance(fields, dict) and
len(fields) > 0 and
all(isinstance(n, str) and isinstance(t, type)
for n, t in fields.items())
for fields in cls.id_fields.values())

def __str__(cls):
return f"v{cls.major}.{cls.minor}"
Expand Down Expand Up @@ -133,6 +140,8 @@ class Version(ABC, metaclass=MetaVersion):
# list of the same, with the empty string mapping to a list of topmost
# object list names.
graph = None
# A map of object names and dictionaries of their ID fields and types
id_fields = None

@classmethod
@abstractmethod
Expand Down
7 changes: 7 additions & 0 deletions kcidb_io/schema/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class V1(Version):
minor = 0
json = dict(title="v1")
graph = {"": []}
id_fields = {}

class V2(V1):
major = 2
minor = 0
json = dict(title="v2")
graph = {"": []}
id_fields = {}

@staticmethod
def _inherit(data):
Expand All @@ -31,12 +33,14 @@ class V2D1(V2):
minor = 1
json = dict(title="v2.1")
graph = {"": []}
id_fields = {}

class V3(V2D1):
major = 3
minor = 0
json = dict(title="v3")
graph = {"": []}
id_fields = {}

@staticmethod
def _inherit(data):
Expand Down Expand Up @@ -138,12 +142,14 @@ class V1(Version):
minor = 0
json = dict(title="v1")
graph = {"": []}
id_fields = {}

class V2A(V1):
major = 2
minor = 0
json = dict(title="v2a")
graph = {"": []}
id_fields = {}

@staticmethod
def _inherit(data):
Expand All @@ -154,6 +160,7 @@ class V2B(V1):
minor = 0
json = dict(title="v2b")
graph = {"": []}
id_fields = {}

@staticmethod
def _inherit(data):
Expand Down
6 changes: 6 additions & 0 deletions kcidb_io/schema/v01_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ class Version(AbstractVersion):
"builds": ["tests"],
"tests": []
}
# A map of object names and dictionaries of their ID fields and types
id_fields = dict(
revisions=dict(origin=str, origin_id=str),
builds=dict(origin=str, origin_id=str),
tests=dict(origin=str, origin_id=str),
)

@classmethod
def _get_version(cls, data):
Expand Down
7 changes: 7 additions & 0 deletions kcidb_io/schema/v02_00.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,13 @@ class Version(PreviousVersion):
"tests": []
}

# A map of object names and dictionaries of their ID fields and types
id_fields = dict(
revisions=dict(id=str),
builds=dict(id=str),
tests=dict(id=str),
)

@classmethod
def _get_version(cls, data):
"""
Expand Down
7 changes: 7 additions & 0 deletions kcidb_io/schema/v04_00.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,13 @@ class Version(PreviousVersion):
"tests": []
}

# A map of object names and dictionaries of their ID fields and types
id_fields = dict(
checkouts=dict(id=str),
builds=dict(id=str),
tests=dict(id=str),
)

@staticmethod
def _inherit(data):
"""
Expand Down
9 changes: 9 additions & 0 deletions kcidb_io/schema/v04_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,12 @@ class Version(PreviousVersion):
"issues": ["incidents"],
"incidents": [],
}

# A map of object names and dictionaries of their ID fields and types
id_fields = dict(
checkouts=dict(id=str),
builds=dict(id=str),
tests=dict(id=str),
issues=dict(id=str),
incidents=dict(id=str),
)

0 comments on commit 98f516f

Please sign in to comment.