about summary refs log blame commit diff
path: root/web/panettone/src/migrations/1-init-schema.lisp
blob: 3be6c4fcc0d074b669cb4d95e8bc27f30591ec79 (plain) (tree)






















                                                                              
"Initialize the database schema from before migrations were added"

(defun ddl/create-issue-status ()
  "Issue DDL to create the `issue-status' type, if it doesn't exist"
  (unless (query (:select (:exists (:select 1
                                    :from 'pg_type
                                    :where (:= 'typname "issue_status"))))
                 :single)
    (query (sql-compile
            `(:create-enum issue-status ,panettone.model:+issue-statuses+)))))

(defun ddl/create-tables ()
  "Issue DDL to create all tables, if they don't already exist."
  (dolist (table '(panettone.model:issue
                   panettone.model:issue-comment
                   panettone.model:issue-event
                   panettone.model:user-settings))
    (unless (table-exists-p (dao-table-name table))
      (create-table table))))

(defun up ()
  (ddl/create-issue-status)
  (ddl/create-tables))