From 2023b37b1ea8ceba532c60cf280542b0e2e17e46 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 31 Dec 2023 06:14:37 +0200 Subject: Add gnosis-db-version Version for gnosis-db current implementation. Remove duplicate code as well. --- gnosis.el | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/gnosis.el b/gnosis.el index 55ed3cb..4e7b577 100644 --- a/gnosis.el +++ b/gnosis.el @@ -61,6 +61,9 @@ WARNING: Do not change this value!") (defvar gnosis-testing nil "When t, warn user he is in a testing environment.") +(defconst gnosis-db-version 1 + "Gnosis database version.") + (cl-defun gnosis-select (value table &optional (restrictions '1=1)) "Select VALUE from TABLE, optionally with RESTRICTIONS." (gnosis-db-init) @@ -808,14 +811,7 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." :on-delete :cascade))) (defun gnosis-db-init () - "Create gnosis database." - (cond - ;; if gnosis-dir does not exist, create it - ((not (file-directory-p gnosis-dir)) - (make-directory gnosis-dir)) - ;; if gnosis-images-dir does not exist, create it - ((not (and gnosis-images-dir (file-directory-p gnosis-images-dir))) - (make-directory gnosis-images-dir))) + "Create gnosis essential directories & database." ;; Create gnosis-dir (unless (file-exists-p gnosis-dir) (make-directory gnosis-dir) @@ -826,6 +822,7 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." (unless (length= (emacsql gnosis-db [:select name :from sqlite-master :where (= type table)]) 6) ;; Enable foreign keys (emacsql gnosis-db "PRAGMA foreign_keys = ON") + (emacsql gnosis-db (format "PRAGMA user_version = %s" gnosis-db-version)) ;; Create decks table (gnosis--create-table 'decks gnosis-db-schema-decks) ;; Create notes table -- cgit v1.2.3