refactor(web/panettone): Remove prevalence

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
This commit is contained in:
Griffin Smith 2020-07-28 00:09:36 -04:00 committed by glittershark
parent 31f9ee58d0
commit e8f893ee10
4 changed files with 4 additions and 115 deletions

View file

@ -70,13 +70,11 @@ in {
serviceConfig = { serviceConfig = {
DynamicUser = true; DynamicUser = true;
Restart = "always"; Restart = "always";
StateDirectory = "panettone";
EnvironmentFile = cfg.secretsFile; EnvironmentFile = cfg.secretsFile;
}; };
environment = { environment = {
PANETTONE_PORT = toString cfg.port; PANETTONE_PORT = toString cfg.port;
PANETTONE_DATA_DIR = "/var/lib/panettone";
PGHOST = "localhost"; PGHOST = "localhost";
PGUSER = cfg.dbUser; PGUSER = cfg.dbUser;
PGDATABASE = cfg.dbName; PGDATABASE = cfg.dbName;

View file

@ -4,7 +4,6 @@ depot.nix.buildLisp.program {
name = "panettone"; name = "panettone";
deps = with depot.third_party.lisp; [ deps = with depot.third_party.lisp; [
cl-prevalence
cl-who cl-who
drakma drakma
defclass-std defclass-std

View file

@ -25,7 +25,6 @@
(defpackage panettone (defpackage panettone
(:use :cl :panettone.util :klatre :easy-routes :iterate) (:use :cl :panettone.util :klatre :easy-routes :iterate)
(:import-from :cl-prevalence :get-id)
(:import-from :defclass-std :defclass/std) (:import-from :defclass-std :defclass/std)
(:import-from :alexandria :if-let :when-let) (:import-from :alexandria :if-let :when-let)
(:import-from (:import-from

View file

@ -5,26 +5,6 @@
;;; Data model ;;; 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 () (defclass/std user ()
((cn dn mail displayname :type string))) ((cn dn mail displayname :type string)))
@ -99,84 +79,6 @@ successful, `nil' otherwise"
(defun author (object) (defun author (object)
(find-user-by-dn (author-dn object))) (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 ;;; Views
;;; ;;;
@ -538,22 +440,16 @@ global postgresql connection (eg as initialized by
"Hunchentoot acceptor for Panettone's web server.") "Hunchentoot acceptor for Panettone's web server.")
(defun migrate-db () (defun migrate-db ()
"Migrate the database to the latest version of the schema "Migrate the database to the latest version of the schema"
(model:ddl/init))
In this iteration, intiialize the DDL and move all data from the prevalence (defun start-panettone (&key port
snapshot to the DB. In future iterations, this will do things like adding new
tables and columns"
(model:ddl/init)
(prevalence->postgresql *p-system*))
(defun start-panettone (&key port data-dir
(ldap-host "localhost") (ldap-host "localhost")
(ldap-port 389) (ldap-port 389)
postgres-params) postgres-params)
(connect-ldap :host ldap-host (connect-ldap :host ldap-host
:port ldap-port) :port ldap-port)
(initialize-persistence data-dir)
(apply #'model:connect-postgres postgres-params) (apply #'model:connect-postgres postgres-params)
(migrate-db) (migrate-db)
@ -563,12 +459,10 @@ tables and columns"
(defun main () (defun main ()
(let ((port (integer-env "PANETTONE_PORT" :default 6161)) (let ((port (integer-env "PANETTONE_PORT" :default 6161))
(ldap-port (integer-env "LDAP_PORT" :default 389)) (ldap-port (integer-env "LDAP_PORT" :default 389)))
(data-dir (or (uiop:getenvp "PANETTONE_DATA_DIR") "/var/lib/panettone")))
(setq hunchentoot:*show-lisp-backtraces-p* nil) (setq hunchentoot:*show-lisp-backtraces-p* nil)
(setq hunchentoot:*log-lisp-backtraces-p* nil) (setq hunchentoot:*log-lisp-backtraces-p* nil)
(start-panettone :port port (start-panettone :port port
:data-dir data-dir
:ldap-port ldap-port) :ldap-port ldap-port)
(sb-thread:join-thread (sb-thread:join-thread
(find-if (lambda (th) (find-if (lambda (th)
@ -579,6 +473,5 @@ tables and columns"
(comment (comment
(setq hunchentoot:*catch-errors-p* nil) (setq hunchentoot:*catch-errors-p* nil)
(start-panettone :port 6161 (start-panettone :port 6161
:data-dir "/tmp/panettone"
:ldap-port 3899) :ldap-port 3899)
) )