Skip to content

Commit

Permalink
chore: move queries into separate module for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <[email protected]>
  • Loading branch information
vsoch committed Jun 7, 2024
1 parent 8723a7d commit 53db0a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
22 changes: 22 additions & 0 deletions jobspec/subsystem/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
create_subsystem_sql = """
CREATE TABLE subsystems (
name TEXT PRIMARY KEY NOT NULL
);"""

create_nodes_sql = """CREATE TABLE nodes (
subsystem TEXT NOT NULL,
label TEXT NOT NULL,
type TEXT NOT NULL,
basename TEXT NOT NULL,
name TEXT NOT NULL,
id INTEGER NOT NULL,
FOREIGN KEY(subsystem) REFERENCES subsystems(name),
UNIQUE (subsystem, label)
);"""

create_attributes_sql = """CREATE TABLE attributes (
name TEXT NOT NULL,
value TEXT NOT NULL,
node TEXT NOT NULL,
FOREIGN KEY(node) REFERENCES nodes(label)
);"""
24 changes: 4 additions & 20 deletions jobspec/subsystem/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sqlite3

import jobspec.core as core
import jobspec.subsystem.queries as queries
import jobspec.utils as utils
from jobspec.logger import LogColors, logger

Expand Down Expand Up @@ -41,26 +42,9 @@ def create_tables(self):
# them for anything - we are going to parse them
# into node attributes instead.
create_sql = [
"""
CREATE TABLE subsystems (
name TEXT PRIMARY KEY NOT NULL
);""",
"""CREATE TABLE nodes (
subsystem TEXT NOT NULL,
label TEXT NOT NULL,
type TEXT NOT NULL,
basename TEXT NOT NULL,
name TEXT NOT NULL,
id INTEGER NOT NULL,
FOREIGN KEY(subsystem) REFERENCES subsystems(name),
UNIQUE (subsystem, label)
);""",
"""CREATE TABLE attributes (
name TEXT NOT NULL,
value TEXT NOT NULL,
node TEXT NOT NULL,
FOREIGN KEY(node) REFERENCES nodes(label)
);""",
queries.create_subsystem_sql,
queries.create_nodes_sql,
queries.create_attributes_sql,
]
for sql in create_sql:
cursor.execute(sql)
Expand Down

0 comments on commit 53db0a8

Please sign in to comment.