diff options
author | Griffin Smith <grfn@gws.fyi> | 2020-07-28T04·09-0400 |
---|---|---|
committer | glittershark <grfn@gws.fyi> | 2020-07-29T01·57+0000 |
commit | e8f893ee100e1c85e08dbfd7244e5c674266c3bc (patch) | |
tree | ea6000ef906eed583aa48dd1e9f829b549817936 /web/panettone/src/panettone.lisp | |
parent | 31f9ee58d0c91d02d96d29ea6e09bf0e4f9c5b92 (diff) |
refactor(web/panettone): Remove prevalence r/1505
Now that we've migrated over all the data to postgresql, we can get rid of cl-prevalence as a dependency from Panettone along with all code that mentions it. Change-Id: I945f50a88fea5770aac5b4a058342b8269c0bea2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1495 Reviewed-by: kanepyork <rikingcoding@gmail.com> Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'web/panettone/src/panettone.lisp')
-rw-r--r-- | web/panettone/src/panettone.lisp | 115 |
1 files changed, 4 insertions, 111 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp index d19e3066b26d..b85a2e91cc6f 100644 --- a/web/panettone/src/panettone.lisp +++ b/web/panettone/src/panettone.lisp @@ -5,26 +5,6 @@ ;;; Data model ;;; -(deftype issue-status () '(member :open :closed)) - -(defclass/std issue-comment () - ((body :type string) - (author-dn :type string) - (created-at :type local-time:timestamp - :std (local-time:now))) - (:documentation - "DEPRECATED: use `PANETTONE.MODEL::ISSUE-COMMENT' instead")) - -(defclass/std issue (cl-prevalence:object-with-id) - ((subject body :type string :std "") - (author-dn :type string) - (comments :std nil :type list :with-prefix) - (status :std :open :type issue-status) - (created-at :type local-time:timestamp - :std (local-time:now))) - (:documentation - "DEPRECATED: use `PANETTONE.MODEL::ISSUE' instead")) - (defclass/std user () ((cn dn mail displayname :type string))) @@ -100,84 +80,6 @@ successful, `nil' otherwise" (find-user-by-dn (author-dn object))) ;;; -;;; Persistence -;;; - -(defvar *p-system* nil - "The persistence system for this instance of Panettone") - -(defun initialize-persistence (data-dir) - "Initialize the Panettone persistence system, storing data in DATA-DIR" - (ensure-directories-exist data-dir) - (setq *p-system* - (cl-prevalence:make-prevalence-system - (concatenate 'string - data-dir - "/snapshot.xml"))) - - - (when (null (cl-prevalence:find-all-objects *p-system* 'issue)) - (cl-prevalence:tx-create-id-counter *p-system*))) - -(defun prevalence->postgresql (system &key force) - "Idempotently migrate all data from the cl-prevalence system SYSTEM into the -global postgresql connection (eg as initialized by -`model:connect-postgres'). With FORCE=t, will clear the database first" - (pomo:with-transaction (prevalence->postgresql) - (when force - (pomo:query (:delete-from 'issues))) - (iter - (for issue in (cl-prevalence:find-all-objects system 'issue)) - (counting - (unless (model:issue-exists-p (get-id issue)) - (model:create-issue - :id (get-id issue) - :subject (subject issue) - :body (or (body issue) "") - :status (status issue) - :author-dn (author-dn issue) - :created-at (created-at issue))) - into num-issues) - (sum - (iter - (for comment in (issue-comments issue)) - (counting - (unless (pomo:query - (:select - (:exists - (:select 1 - :from 'issue_comments - :where (:and - (:= 'issue_id (get-id issue)) - (:= 'body (body comment)) - (:= 'author_dn (author-dn comment)))))) - :single) - (model:create-issue-comment - :body (body comment) - :author-dn (author-dn comment) - :issue-id (get-id issue) - :created-at (created-at comment))))) - into num-comments) - (finally - (let ((next-id (pomo:query - (:select (:+ 1 (:max 'id)) - :from 'issues) - :single))) - (pomo:query - (pomo:sql-compile - `(:alter-sequence issues_id_seq :restart ,next-id)))) - (format t "Created ~A issues and ~A comments~&" - num-issues num-comments) - (return (values num-issues num-comments)))))) - -(comment - (initialize-persistence "/home/grfn/code/depot/web/panettone/") - (model:connect-postgres) - (model:ddl/init) - (prevalence->postgresql *p-system* :force t) - ) - -;;; ;;; Views ;;; @@ -538,22 +440,16 @@ global postgresql connection (eg as initialized by "Hunchentoot acceptor for Panettone's web server.") (defun migrate-db () - "Migrate the database to the latest version of the schema - -In this iteration, intiialize the DDL and move all data from the prevalence -snapshot to the DB. In future iterations, this will do things like adding new -tables and columns" - (model:ddl/init) - (prevalence->postgresql *p-system*)) + "Migrate the database to the latest version of the schema" + (model:ddl/init)) -(defun start-panettone (&key port data-dir +(defun start-panettone (&key port (ldap-host "localhost") (ldap-port 389) postgres-params) (connect-ldap :host ldap-host :port ldap-port) - (initialize-persistence data-dir) (apply #'model:connect-postgres postgres-params) (migrate-db) @@ -563,12 +459,10 @@ tables and columns" (defun main () (let ((port (integer-env "PANETTONE_PORT" :default 6161)) - (ldap-port (integer-env "LDAP_PORT" :default 389)) - (data-dir (or (uiop:getenvp "PANETTONE_DATA_DIR") "/var/lib/panettone"))) + (ldap-port (integer-env "LDAP_PORT" :default 389))) (setq hunchentoot:*show-lisp-backtraces-p* nil) (setq hunchentoot:*log-lisp-backtraces-p* nil) (start-panettone :port port - :data-dir data-dir :ldap-port ldap-port) (sb-thread:join-thread (find-if (lambda (th) @@ -579,6 +473,5 @@ tables and columns" (comment (setq hunchentoot:*catch-errors-p* nil) (start-panettone :port 6161 - :data-dir "/tmp/panettone" :ldap-port 3899) ) |