Skip to content

Commit 0c46125

Browse files
author
Ben Elsworth
committed
db shcema config check
1 parent e0cbcf0 commit 0c46125

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

Diff for: config/db_schema_nodes.schema.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$schema: "http://json-schema.org/draft-07/schema#"
2+
description: information for each data set
3+
properties:
4+
properties:
5+
type: object
6+
description: information on node/rel properties
7+
required:
8+
type: array
9+
description: which properties are required
10+
index:
11+
type: string
12+
description: the property to use as an index
13+
meta:
14+
type: object
15+
description: source of the data
16+
17+
required:
18+
- properties
19+
- required
20+
- index
21+
- meta

Diff for: config/db_schema_rels.schema.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$schema: "http://json-schema.org/draft-07/schema#"
2+
description: information for each data set
3+
properties:
4+
properties:
5+
type: object
6+
description: information on node/rel properties
7+
required:
8+
type: array
9+
description: which properties are required
10+
11+
required:
12+
- properties
13+
- required

Diff for: workflow/Snakefile

+16-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ THREADS=env_configs['threads']
2525
DATA_CONFIG = os.path.join(CONFIG_PATH,"data_integration.yaml")
2626
DATA_CONFIG_SCHEMA = "config/data_integration.schema.yaml"
2727
DB_SCHEMA = os.path.join(CONFIG_PATH,"db_schema.yaml")
28-
DB_SCHEMA_SCHEMA = "config/db_schema.schema.yaml"
28+
DB_SCHEMA_NODES_SCHEMA = "config/db_schema_nodes.schema.yaml"
29+
DB_SCHEMA_RELS_SCHEMA = "config/db_schema_rels.schema.yaml"
2930

3031
configfile: DATA_CONFIG
3132

@@ -36,7 +37,7 @@ rule check_configs:
3637
DATA_CONFIG,
3738
DB_SCHEMA
3839
run:
39-
#maybe add this as a rule
40+
#validata data integration config file
4041
if NODEDIR in config:
4142
nodes = config[NODEDIR]
4243
for i in nodes:
@@ -47,11 +48,19 @@ rule check_configs:
4748
validate(rels[i], os.path.join(os.getcwd(),DATA_CONFIG_SCHEMA))
4849

4950
#validate db schema config file
50-
#with open(os.path.join(CONFIG_PATH,"db_schema.yaml")) as file:
51-
# db_schema = yaml.load(file,Loader=yaml.FullLoader)
52-
#print(db_schema)
53-
# if 'meta_nodes' in db_schema:
54-
# print(db_schema['meta_nodes'])
51+
with open(os.path.join(CONFIG_PATH,"db_schema.yaml")) as file:
52+
db_schema = yaml.load(file,Loader=yaml.FullLoader)
53+
if 'meta_nodes' in db_schema:
54+
nodes = db_schema['meta_nodes']
55+
for i in nodes:
56+
validate(nodes[i], os.path.join(os.getcwd(),DB_SCHEMA_NODES_SCHEMA))
57+
else:
58+
print('The db schame has no nodes!')
59+
exit()
60+
if 'meta_rels' in db_schema:
61+
rels = db_schema['meta_rels']
62+
for i in rels:
63+
validate(rels[i], os.path.join(os.getcwd(),DB_SCHEMA_RELS_SCHEMA))
5564

5665
rule all:
5766
input: f"{SNAKEMAKELOGS}/import_report.log"

0 commit comments

Comments
 (0)