From 98f516fdab85f8353fa830d68948038c2524a2a3 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Fri, 11 Oct 2024 18:07:44 +0300 Subject: [PATCH] schema: Describe object ID fields 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. --- kcidb_io/schema/abstract.py | 9 +++++++++ kcidb_io/schema/test_abstract.py | 7 +++++++ kcidb_io/schema/v01_01.py | 6 ++++++ kcidb_io/schema/v02_00.py | 7 +++++++ kcidb_io/schema/v04_00.py | 7 +++++++ kcidb_io/schema/v04_01.py | 9 +++++++++ 6 files changed, 45 insertions(+) diff --git a/kcidb_io/schema/abstract.py b/kcidb_io/schema/abstract.py index 8262809..05c9829 100644 --- a/kcidb_io/schema/abstract.py +++ b/kcidb_io/schema/abstract.py @@ -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}" @@ -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 diff --git a/kcidb_io/schema/test_abstract.py b/kcidb_io/schema/test_abstract.py index 6e844b2..f41e86b 100644 --- a/kcidb_io/schema/test_abstract.py +++ b/kcidb_io/schema/test_abstract.py @@ -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): @@ -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): @@ -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): @@ -154,6 +160,7 @@ class V2B(V1): minor = 0 json = dict(title="v2b") graph = {"": []} + id_fields = {} @staticmethod def _inherit(data): diff --git a/kcidb_io/schema/v01_01.py b/kcidb_io/schema/v01_01.py index 6f0d98d..deb4d8c 100644 --- a/kcidb_io/schema/v01_01.py +++ b/kcidb_io/schema/v01_01.py @@ -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): diff --git a/kcidb_io/schema/v02_00.py b/kcidb_io/schema/v02_00.py index be6ba41..05ff7ef 100644 --- a/kcidb_io/schema/v02_00.py +++ b/kcidb_io/schema/v02_00.py @@ -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): """ diff --git a/kcidb_io/schema/v04_00.py b/kcidb_io/schema/v04_00.py index 5dd5ddd..648ad6f 100644 --- a/kcidb_io/schema/v04_00.py +++ b/kcidb_io/schema/v04_00.py @@ -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): """ diff --git a/kcidb_io/schema/v04_01.py b/kcidb_io/schema/v04_01.py index f1cd410..4ca23eb 100644 --- a/kcidb_io/schema/v04_01.py +++ b/kcidb_io/schema/v04_01.py @@ -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), + )