diff options
author | Matthias Baumgartner <dev@igsor.net> | 2022-12-18 14:07:56 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2022-12-18 14:07:56 +0100 |
commit | 3165c3609a5061135ff7393747f8dc3f7f7abe0c (patch) | |
tree | 5683aaab759d1930ce59237acde23e673562e87d /bsfs/graph/graph.py | |
parent | edd5390b6db1550f6a80a46f0eaf5f3916997532 (diff) | |
download | bsfs-3165c3609a5061135ff7393747f8dc3f7f7abe0c.tar.gz bsfs-3165c3609a5061135ff7393747f8dc3f7f7abe0c.tar.bz2 bsfs-3165c3609a5061135ff7393747f8dc3f7f7abe0c.zip |
graph schema migration
Diffstat (limited to 'bsfs/graph/graph.py')
-rw-r--r-- | bsfs/graph/graph.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bsfs/graph/graph.py b/bsfs/graph/graph.py index 71973c2..4a36ff6 100644 --- a/bsfs/graph/graph.py +++ b/bsfs/graph/graph.py @@ -5,6 +5,7 @@ A copy of the license is provided with the project. Author: Matthias Baumgartner, 2022 """ # imports +import os import typing # bsfs imports @@ -35,6 +36,8 @@ class Graph(): def __init__(self, backend: TripleStoreBase, user: URI): self._backend = backend self._user = user + # ensure Graph schema requirements + self.migrate(self._backend.schema) def __hash__(self) -> int: return hash((type(self), self._backend, self._user)) @@ -55,7 +58,28 @@ class Graph(): """Return the store's local schema.""" return self._backend.schema + def migrate(self, schema: Schema, append: bool = True) -> 'Graph': + """Migrate the current schema to a new *schema*. + + Appends to the current schema by default; control this via *append*. + The `Graph` may add additional classes to the schema that are required for its interals. + """ + # check args + if not isinstance(schema, Schema): + raise TypeError(schema) + # append to current schema + if append: + schema = schema + self._backend.schema + # add Graph schema requirements + with open(os.path.join(os.path.dirname(__file__), 'schema.nt'), mode='rt', encoding='UTF-8') as ifile: + schema = schema + Schema.from_string(ifile.read()) + # migrate schema in backend + # FIXME: consult access controls! + self._backend.schema = schema + # return self + return self + def nodes(self, node_type: URI, guids: typing.Iterable[URI]) -> _nodes.Nodes: """ node_type = self.schema.node(node_type) |