From 49688e405591a69fb378670a07873940537fa330 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 13 May 2024 21:21:13 +0200 Subject: [PATCH] storage/tracking: create-index function --- storage/tracking.lisp | 14 +++++++++++++- test/test-storage.lisp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/storage/tracking.lisp b/storage/tracking.lisp index 1337555..31295ca 100644 --- a/storage/tracking.lisp +++ b/storage/tracking.lisp @@ -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)))))) diff --git a/test/test-storage.lisp b/test/test-storage.lisp index 788af66..c3386e5 100644 --- a/test/test-storage.lisp +++ b/test/test-storage.lisp @@ -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)))