summaryrefslogtreecommitdiff
path: root/model/sql
diff options
context:
space:
mode:
Diffstat (limited to 'model/sql')
-rw-r--r--model/sql/migration000.sql41
-rw-r--r--model/sql/migration001.sql8
2 files changed, 49 insertions, 0 deletions
diff --git a/model/sql/migration000.sql b/model/sql/migration000.sql
new file mode 100644
index 0000000..061eefd
--- /dev/null
+++ b/model/sql/migration000.sql
@@ -0,0 +1,41 @@
+-- Database schema version 0 corresponds to what ceres v0.4.0 used.
+
+PRAGMA foreign_keys = ON;
+
+CREATE TABLE metadata (
+ key TEXT PRIMARY KEY,
+ value TEXT
+);
+
+CREATE TABLE recipes (
+ id INTEGER PRIMARY KEY,
+ title TEXT NOT NULL,
+ portions INTEGER NOT NULL,
+ url TEXT NOT NULL,
+ notes TEXT NOT NULL,
+ created INTEGER NOT NULL, -- Unix time stamp
+ last_changed INTEGER NOT NULL -- Unix time stamp
+);
+
+CREATE TABLE steps (
+ id INTEGER PRIMARY KEY,
+ 'index' INTEGER NOT NULL,
+ text TEXT NOT NULL,
+ recipe INTEGER NOT NULL,
+ FOREIGN KEY(recipe) REFERENCES recipes(id)
+);
+
+CREATE TABLE ingredients (
+ id INTEGER PRIMARY KEY,
+ 'index' INTEGER NOT NULL,
+ amount REAL NOT NULL,
+ unit TEXT NOT NULL,
+ 'type' TEXT NOT NULL,
+ step INTEGER NOT NULL,
+ FOREIGN KEY(step) REFERENCES steps(id)
+);
+
+INSERT INTO metadata
+ (key, value)
+VALUES
+ ('version', 'v0.4.0');
diff --git a/model/sql/migration001.sql b/model/sql/migration001.sql
new file mode 100644
index 0000000..64c7ee3
--- /dev/null
+++ b/model/sql/migration001.sql
@@ -0,0 +1,8 @@
+-- Database schema 1 is the first schema with numerical versioning.
+
+DELETE FROM metadata WHERE key = 'version';
+
+INSERT INTO metadata
+ (key, value)
+VALUES
+ ('schema_version', '2');