From 7cd3a096a975801a07fb3ff06b6fac70e17234ce Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Sun, 3 Nov 2024 15:49:43 +0100
Subject: model: Implement favorite recipes

This adds the ability to store a flag `is_favorite` inside the database.
The corresponding SQL migration is part of this commit.

Furthermore the Go code in the model package is adapted.
---
 model/sql/migration002.sql | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 model/sql/migration002.sql

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

diff --git a/model/sql/migration002.sql b/model/sql/migration002.sql
new file mode 100644
index 0000000..89837b3
--- /dev/null
+++ b/model/sql/migration002.sql
@@ -0,0 +1,30 @@
+-- Database schema 2 adds the ability to save recipes as favorites.
+
+CREATE TABLE recipes_new (
+	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
+	is_favorite  BOOLEAN NOT NULL DEFAULT FALSE
+);
+
+INSERT INTO
+	recipes_new
+	(id, title, portions, url, notes, created, last_changed, is_favorite)
+SELECT
+	id, title, portions, url, notes, created, last_changed, FALSE
+FROM recipes;
+
+DROP TABLE recipes;
+
+ALTER TABLE recipes_new RENAME TO recipes;
+
+UPDATE
+	metadata
+SET
+	value = '3'
+WHERE
+	key = 'schema_version';
-- 
cgit v1.3

