Commit c99a354a authored by Samuel GAIST's avatar Samuel GAIST

[database] Cleanup handling of schema version

This way beat/beat.core> doesn't depend on updating the
is_v1 flag.
parent af9db985
Pipeline #29340 passed with stage
in 8 minutes and 43 seconds
......@@ -251,7 +251,6 @@ class Database(object):
self.errors = []
self.data = None
self.is_v1 = False
# if the user has not provided a cache, still use one for performance
dataformat_cache = dataformat_cache if dataformat_cache is not None else {}
......@@ -306,17 +305,14 @@ class Database(object):
self.code_path = self.storage.code.path
self.code = self.storage.code.load()
schema_version = int(self.data.get("schema_version", 1))
if schema_version == 1:
self.is_v1 = True
if self.schema_version == 1:
self._load_v1(dataformat_cache)
elif schema_version == 2:
elif self.schema_version == 2:
self._load_v2(dataformat_cache)
else:
raise RuntimeError(
"Invalid schema version {schema_version}".format(
schema_version=schema_version
schema_version=self.schema_version
)
)
......@@ -405,7 +401,7 @@ class Database(object):
def sets(self, protocol):
"""The declaration of a specific set in the database protocol"""
if self.is_v1:
if self.schema_version == 1:
data = self.protocol(protocol)["sets"]
else:
protocol = self.protocol(protocol)
......@@ -426,7 +422,7 @@ class Database(object):
def set_names(self, protocol):
"""The names of sets in a given protocol for this database"""
if self.is_v1:
if self.schema_version == 1:
data = self.protocol(protocol)["sets"]
else:
protocol = self.protocol(protocol)
......@@ -451,7 +447,7 @@ class Database(object):
"""
if self.is_v1:
if self.schema_version == 1:
view_definition = self.set(protocol_name, set_name)
else:
protocol = self.protocol(protocol_name)
......@@ -599,7 +595,7 @@ class Database(object):
for k in self.dataformats.values():
k.export(prefix)
if not self.is_v1:
if self.schema_version != 1:
for protocol in self.protocols.values():
protocol_template = ProtocolTemplate(self.prefix, protocol["template"])
protocol_template.export(prefix)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment