Function: forge--db-update-schema
forge--db-update-schema is a byte-compiled function defined in
forge-db.el.
Signature
(forge--db-update-schema DB VERSION)
Source Code
;; Defined in ~/.emacs.d/elpa/forge-20260408.1922/forge-db.el
(defun forge--db-update-schema (db version)
(cl-macrolet
((up (to &rest body)
`(when (= (1+ version) ,to)
(message "Upgrading Forge database from version %s to %s..."
version ,to)
,@body
(closql--db-set-version db ,to)
(message "Upgrading Forge database from version %s to %s...done"
version ,to)
(setq version ,to))))
(up 3
(emacsql db [:create-table pullreq-review-request $S1]
(cdr (assq 'pullreq-review-request forge--db-table-schemata))))
(up 4
(emacsql db [:drop-table notification])
(pcase-dolist (`(,table . ,schema) forge--db-table-schemata)
(when (memq table '(notification
mark issue-mark pullreq-mark))
(emacsql db [:create-table $i1 $S2] table schema)))
(emacsql db [:alter-table issue :add-column marks :default $s1] 'eieio-unbound)
(emacsql db [:alter-table pullreq :add-column marks :default $s1] 'eieio-unbound))
(up 5
(emacsql db [:alter-table repository :add-column selective-p :default nil]))
(up 6
(emacsql db [:alter-table repository :add-column worktree :default nil]))
(up 7
(emacsql db [:alter-table issue :add-column note :default nil])
(emacsql db [:alter-table pullreq :add-column note :default nil])
(emacsql db [:create-table milestone $S1]
(cdr (assq 'milestone forge--db-table-schemata)))
(emacsql db [:alter-table repository :add-column milestones :default $s1]
'eieio-unbound)
(pcase-dolist (`(,repo-id ,issue-id ,milestone)
(emacsql db [:select [repository id milestone]
:from issue
:where (notnull milestone)]))
(unless (stringp milestone)
(oset (forge-get-issue issue-id) milestone
(forge--object-id repo-id (cdar milestone)))))
(pcase-dolist (`(,repo-id ,pullreq-id ,milestone)
(emacsql db [:select [repository id milestone]
:from pullreq
:where (notnull milestone)]))
(unless (stringp milestone)
(oset (forge-get-pullreq pullreq-id) milestone
(forge--object-id repo-id (cdar milestone))))))
(up 8
(emacsql db [:alter-table pullreq :add-column base-rev :default nil])
(emacsql db [:alter-table pullreq :add-column head-rev :default nil])
(emacsql db [:alter-table pullreq :add-column draft-p :default nil]))
(up 9
(emacsql db [:alter-table pullreq :add-column their-id :default nil])
(emacsql db [:alter-table issue :add-column their-id :default nil]))
(up 10
(emacsql db [:alter-table pullreq :add-column slug :default nil])
(emacsql db [:alter-table issue :add-column slug :default nil])
(pcase-dolist (`(,id ,number ,type)
(emacsql
db
[:select [pullreq:id pullreq:number repository:class]
:from pullreq
:join repository
:on (= pullreq:repository repository:id)]))
(let ((gitlabp (memq type
(append (closql-where-class-in
'forge-gitlab-repository--eieio-childp)
nil))))
(emacsql db [:update pullreq :set (= slug $s1) :where (= id $s2)]
(format "%s%s" (if gitlabp "!" "#") number)
id)))
(pcase-dolist (`(,id ,number)
(emacsql db [:select [id number] :from issue]))
(emacsql db [:update issue :set (= slug $s1) :where (= id $s2)]
(format "#%s" number)
id)))
(up 11
(emacsql db [:drop-table notification])
(emacsql db [:create-table notification $S1]
(cdr (assq 'notification forge--db-table-schemata)))
(emacsql db [:alter-table pullreq :rename-column unread-p :to status])
(emacsql db [:alter-table issue :rename-column unread-p :to status])
(emacsql db [:alter-table pullreq :add-column saved-p :default nil])
(emacsql db [:alter-table issue :add-column saved-p :default nil]))
(up 12
(emacsql db [:drop-table notification])
(emacsql db [:create-table notification $S1]
(cdr (assq 'notification forge--db-table-schemata)))
(dolist (id (emacsql db [:select id :from issue :where (= state 'closed)]))
(emacsql db [:update issue :set (= state 'completed) :where (= id $s1)]
id))
(dolist (id (emacsql db [:select id :from issue :where (isnull status)]))
(emacsql db [:update issue :set (= state 'done) :where (= id $s1)]
id))
(dolist (id (emacsql db [:select id :from pullreq :where (= state 'closed)]))
(emacsql db [:update pullreq :set (= state 'rejected) :where (= id $s1)]
id))
(dolist (id (emacsql db [:select id :from pullreq :where (isnull status)]))
(emacsql db [:update pullreq :set (= state 'done) :where (= id $s1)]
id))
(emacsql db [:alter-table repository :add-column issues-until :default nil])
(emacsql db [:alter-table repository :add-column pullreqs-until :default nil]))
(up 13
(dolist (id (emacsql db [:select id :from repository
:where (isnull issues-until)]))
(emacsql
db [:update repository :set (= issues-until $s1) :where (= id $s2)]
(forge-sql1 [:select [updated] :from issue
:where (= repository $s1)
:order-by [(desc updated)]
:limit 1]
id)
id))
(dolist (id (emacsql db [:select id :from repository
:where (isnull pullreqs-until)]))
(emacsql
db [:update repository :set (= pullreqs-until $s1) :where (= id $s2)]
(forge-sql1 [:select [updated] :from pullreq
:where (= repository $s1)
:order-by [(desc updated)]
:limit 1]
id)
id))
(emacsql db [:alter-table repository :rename-column sparse-p :to condition])
(pcase-dolist (`(,id ,not-tracked)
(emacsql db [:select [id condition] :from repository]))
(emacsql
db [:update repository :set (= condition $s1) :where (= id $s2)]
(if not-tracked :known :tracked)
id)))
(up 14
(emacsql db [:alter-table repository :add-column teams :default nil]))
(up 15
(emacsql db [:create-table discussion $S1]
(cdr (assq 'discussion forge--db-table-schemata)))
(emacsql db [:create-table discussion-category $S1]
(cdr (assq 'discussion-category forge--db-table-schemata)))
(emacsql db [:create-table discussion-label $S1]
(cdr (assq 'discussion-label forge--db-table-schemata)))
(emacsql db [:create-table discussion-mark $S1]
(cdr (assq 'discussion-mark forge--db-table-schemata)))
(emacsql db [:create-table discussion-post $S1]
(cdr (assq 'discussion-post forge--db-table-schemata)))
(emacsql db [:create-table discussion-reply $S1]
(cdr (assq 'discussion-reply forge--db-table-schemata)))
(emacsql db [:alter-table repository :add-column discussion-categories
:default 'eieio-unbound])
(emacsql db [:alter-table repository :add-column discussions
:default 'eieio-unbound])
(emacsql db [:alter-table repository :add-column discussions-p
:default nil])
(emacsql db [:alter-table repository :add-column discussions-until
:default nil]))
))