You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
(in-package :ritherdon-archive/models)
|
|
|
|
;;;
|
|
|
|
;;; DB connection, migrations.
|
|
|
|
;;;
|
|
|
|
|
|
|
|
(defparameter *tables* '(product user)
|
|
|
|
"List of the DB tables that need to be checked for migrations.")
|
|
|
|
|
|
|
|
(defun connect (&optional (db-name *db-name*))
|
|
|
|
"Connect to the DB."
|
|
|
|
;; *db* could be mito:*connection*
|
|
|
|
(log:debug "connecting to ~a~&" *db-name*)
|
|
|
|
(setf *db* (mito:connect-toplevel :sqlite3 :database-name db-name)))
|
|
|
|
|
|
|
|
(defun ensure-tables-exist ()
|
|
|
|
"Run SQL to create the missing tables."
|
|
|
|
(unless mito::*connection*
|
|
|
|
(connect))
|
|
|
|
(mapcar #'mito:ensure-table-exists *tables*))
|
|
|
|
|
|
|
|
(defun migrate-all ()
|
|
|
|
"Migrate the tables after we changed the class definition."
|
|
|
|
(mapcar #'mito:migrate-table *tables*))
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Entry points
|
|
|
|
;;
|
|
|
|
(defun init-db ()
|
|
|
|
"Connect to the DB, run the required migrations and define a couple base user roles."
|
|
|
|
(ensure-tables-exist))
|