aboutsummaryrefslogtreecommitdiff
path: root/captain/sql
diff options
context:
space:
mode:
Diffstat (limited to 'captain/sql')
-rw-r--r--captain/sql/create.sql2
-rwxr-xr-xcaptain/sql/scan_instructions.sh19
2 files changed, 20 insertions, 1 deletions
diff --git a/captain/sql/create.sql b/captain/sql/create.sql
index 9fd00d0..e8198e4 100644
--- a/captain/sql/create.sql
+++ b/captain/sql/create.sql
@@ -5,7 +5,7 @@ CREATE TABLE jobs(id INTEGER PRIMARY KEY, player INTEGER DEFAULT NULL, status IN
CREATE TABLE tasks(job INTEGER, task INTEGER, status INTEGER, FOREIGN KEY(job) REFERENCES jobs(id));
-CREATE TABLE instructions(id INTEGER PRIMARY KEY, name TEXT NOT NULL, file TEXT NOT NULL);
+CREATE TABLE instructions(id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL);
CREATE_TABLE available(instruction INTEGER, player INTEGER, \
FOREIGN KEY(instruction) REFERENCES instructions(id), \
diff --git a/captain/sql/scan_instructions.sh b/captain/sql/scan_instructions.sh
new file mode 100755
index 0000000..dab98b3
--- /dev/null
+++ b/captain/sql/scan_instructions.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+cmds=`tempfile`
+echo $cmds
+
+for filename in $2/*.json; do
+ # In case it doesn't exist
+ [ -e "$filename" ] || continue
+ name=${filename##*/}
+ echo $name
+ base=${name%.json}
+ echo $base
+
+ echo "INSERT OR IGNORE INTO instructions(name) VALUES('$base');" | cat >> $cmds
+done
+
+sqlite3 $1 < $cmds
+
+rm $cmds