From 118e1c69057e4e7b6ab3e730d5628b4822ed4c4d Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Tue, 15 Oct 2024 21:23:10 +0200
Subject: model: Save int-based schema version in DB

Ceres v0.4.0 used the `git describe` output as database schema and
enforced exactly matching versions between the database and the
executable.

This turned out to be not flexible enough. It is way easier to version
the database separately with a simple integer and require the same
database schema version integer between the application and the
database.

This commit implements this new approach.
---
 model/sql/migration000.sql | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 model/sql/migration000.sql

(limited to 'model/sql/migration000.sql')

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');
-- 
cgit v1.3

