From e8f893ee100e1c85e08dbfd7244e5c674266c3bc Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Tue, 28 Jul 2020 00:09:36 -0400 Subject: 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 Reviewed-by: tazjin Tested-by: BuildkiteCI --- web/panettone/default.nix | 1 - web/panettone/src/packages.lisp | 1 - web/panettone/src/panettone.lisp | 115 ++------------------------------------- 3 files changed, 4 insertions(+), 113 deletions(-) (limited to 'web') diff --git a/web/panettone/default.nix b/web/panettone/default.nix index d3f4829d99..637ccfea9d 100644 --- a/web/panettone/default.nix +++ b/web/panettone/default.nix @@ -4,7 +4,6 @@ depot.nix.buildLisp.program { name = "panettone"; deps = with depot.third_party.lisp; [ - cl-prevalence cl-who drakma defclass-std diff --git a/web/panettone/src/packages.lisp b/web/panettone/src/packages.lisp index 169d8833a7..48db18de3d 100644 --- a/web/panettone/src/packages.lisp +++ b/web/panettone/src/packages.lisp @@ -25,7 +25,6 @@ (defpackage panettone (:use :cl :panettone.util :klatre :easy-routes :iterate) - (:import-from :cl-prevalence :get-id) (:import-from :defclass-std :defclass/std) (:import-from :alexandria :if-let :when-let) (:import-from diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp index d19e3066b2..b85a2e91cc 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))) @@ -99,84 +79,6 @@ successful, `nil' otherwise" (defun author (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 ;;; @@ -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) ) -- cgit 1.4.1