Browse Source

schema.sql, setup_sqlite.sh

Brennen Bearnes 3 years ago
parent
commit
ef62db4fe6
2 changed files with 41 additions and 0 deletions
  1. 18
    0
      schema.sql
  2. 23
    0
      setup_sqlite.sh

+ 18
- 0
schema.sql View File

@@ -0,0 +1,18 @@
1
+-- This creates a table with structure like:
2
+-- id | timestamp | event_type
3
+
4
+CREATE TABLE events(id INTEGER PRIMARY KEY, timestamp TEXT, event_type INTEGER);
5
+
6
+-- Event type will reference the id of a row in event_types - this lets us
7
+-- extend the table later on to include more sensors.
8
+
9
+CREATE TABLE event_types(id INTEGER PRIMARY KEY, name TEXT);
10
+INSERT INTO event_types (id, name) VALUES (1, 'motion');
11
+INSERT INTO event_types (id, name) VALUES (2, 'trap');
12
+
13
+-- You'd log a motion event, like the mouse nosing around the entrance
14
+-- to the trap, with:
15
+-- INSERT INTO events(timestamp, event_type) VALUES (DATETIME(), 1);
16
+
17
+-- And a trap-tipping event a few seconds later with:
18
+-- INSERT INTO events(timestamp, event_type) VALUES (DATETIME(), 2);

+ 23
- 0
setup_sqlite.sh View File

@@ -0,0 +1,23 @@
1
+#!/usr/bin/env bash
2
+
3
+if [ -e mice.db ]; then
4
+  read -p "Overwrite existing mice.db, erasing any existing data? " -n 1 -r
5
+  if [[ $REPLY =~ ^[Yy]$ ]]; then
6
+    rm mice.db
7
+  else
8
+    echo
9
+    echo "No disassemble!"
10
+    exit
11
+  fi
12
+fi
13
+
14
+echo
15
+echo
16
+echo "Creating new mice.db, with schema:"
17
+sqlite3 mice.db < schema.sql
18
+sqlite3 mice.db '.schema'
19
+# sqlite3 mice.db '.schema event_types'
20
+
21
+echo
22
+echo "Event types:"
23
+sqlite3 mice.db 'SELECT * FROM event_types;'

Loading…
Cancel
Save