summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-12-31 06:14:37 +0200
committerThanos Apollo <[email protected]>2023-12-31 06:14:37 +0200
commit2023b37b1ea8ceba532c60cf280542b0e2e17e46 (patch)
tree1867536d66dbe1d76783fa0cc3572ff4e2aa64eb /gnosis.el
parenteb6b112f1d754a285f06d5a9b1e4d18c1ed4b402 (diff)
Add gnosis-db-version
Version for gnosis-db current implementation. Remove duplicate code as well.
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el13
1 files 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