storage/tracking: create-index function

This commit is contained in:
Helmut Merz 2024-05-13 21:21:13 +02:00
parent 935465245f
commit 49688e4055
2 changed files with 14 additions and 1 deletions

View file

@ -7,7 +7,7 @@
(:local-nicknames (:storage :scopes/storage))
(:export #:track #:time-stamp #:data
#:container
#:create-table))
#:create-indexes #:create-table))
(in-package :scopes/storage/tracking)
@ -35,3 +35,15 @@
hf-def
`((timestamp :type timestamptz :not-null t :default current_timestamp)
(data :type ,json-type)))))))
(defun create-indexes (st tname ixs)
(let ((i 1)
(tn (symbol-name tname)))
(dolist (ix ixs)
(let ((ixname (intern (format nil "IDX_~a_~d" tn i))))
(incf i)
(storage:do-sql st
(sxql:create-index ixname :on (cons tname ix)))))
(storage:do-sql st
(sxql:create-index (intern (format nil "IDX_~a_TS" tn))
:on (cons tname '(timestamp))))))

View file

@ -40,4 +40,5 @@
(let ((tr (make-instance 'tracking:track)))
(storage:drop-table st :tracks)
(tracking:create-table st :tracks '(taskid username))
(tracking:create-indexes st :tracks '((taskid) (taskid username)))
(== (tracking:data tr) nil)))