data.lisp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (in-package :cl-user)
  2. (defpackage #:assboard.data
  3. (:nicknames :data)
  4. (:use :cl :postmodern))
  5. (in-package :assboard.data)
  6. ;; Install local-time timestamp reader
  7. (local-time:set-local-time-cl-postgres-readers)
  8. (defvar *db-host* "127.0.0.1" "database host name")
  9. (defvar *db-user* "assboard" "database user")
  10. (defvar *db-pass* "assboard" "database pass")
  11. (defvar *db-name* "assboard" "database name")
  12. (defun start-db-connection (&optional (database *db-name*)
  13. (database-user *db-user*)
  14. (database-password *db-pass*)
  15. (host *db-host*))
  16. "Start the database connection. Reconnects if there is an unconnected
  17. database in *database* which matches the database parameter in the function, it will
  18. be reconnected. Returns boolean on whether the global *database* is now connected."
  19. (unless *database*
  20. (setf *database*
  21. (postmodern:connect database database-user database-password
  22. host :pooled-p t))))
  23. (defclass posting ()
  24. ((id :col-type serial :reader posting-id)
  25. (hash :col-type string :accessor posting-hash :initarg :hash)
  26. (author :col-type string :accessor posting-author :initarg :author)
  27. (status :col-type string :accessor posting-status :initarg :status :col-default "open")
  28. (title :col-type string :accessor posting-title :initarg :title)
  29. (body :col-type string :accessor posting-body :initarg :body)
  30. (maintainer :col-type (or string db-null) :accessor posting-maintainer)
  31. (created-on :col-type timestamptz :reader posting-created-on :col-default (:now))
  32. (updated-on :col-type timestamptz :accessor posting-updated-on :col-default (:now)))
  33. (:metaclass dao-class)
  34. (:keys id))
  35. (deftable posting
  36. (!dao-def)
  37. (!index 'status)
  38. (!index 'author)
  39. (!index 'maintainer))
  40. (defclass raw ()
  41. ((id :col-type serial :reader raw-id)
  42. (crearsigned :col-type string :initarg :clearsigned)
  43. (fingerprint :col-type string :reader raw-fingerprint :initarg :fingerprint)
  44. (timestamp :col-type timestamptz :initarg :timestamp)
  45. (created-on :col-type timestamptz :col-default (:now))
  46. (remote-ip :col-type (or string db-null) :initform (ignore-errors (hunchentoot:real-remote-addr)))
  47. (remote-ua :col-type (or string db-null) :initform (ignore-errors (hunchentoot:user-agent))))
  48. (:metaclass dao-class)
  49. (:keys id))
  50. (deftable raw
  51. (!dao-def))
  52. (defclass posting-edition ()
  53. ((id :col-type serial :reader posting-edition-id)
  54. (posting-id :col-type integer :initarg :posting-id)
  55. (title :col-type string :initarg :title)
  56. (body :col-type string :initarg :body)
  57. (raw-id :col-type integer :initarg :raw-id))
  58. (:metaclass dao-class)
  59. (:keys id))
  60. (deftable posting-edition
  61. (!dao-def)
  62. (!foreign 'posting :posting-id :primary-key)
  63. (!foreign 'raw :raw-id :primary-key))