feat(web/panettone): Create users table
Create a (currently unused) table to store information about users. I'll be manually migrating over all the information about users into this table, then will make a subsequent CL to make the rest of the tables foreign-key into this table Change-Id: I1b1c4b50c4a61326df3382809f701947a2caf536 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11411 Autosubmit: aspen <root@gws.fyi> Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
594600cd4a
commit
413441e2f2
3 changed files with 41 additions and 2 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
"Add a table to store information about users, load the initial set of users
|
||||||
|
from the authentication provider, and change fks for other tables"
|
||||||
|
|
||||||
|
(defun up ()
|
||||||
|
(panettone.model:create-table-if-not-exists
|
||||||
|
'panettone.model:user))
|
|
@ -39,6 +39,22 @@ initialised at launch time.")
|
||||||
;;; Schema
|
;;; Schema
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
|
(defclass user ()
|
||||||
|
((sub :col-type uuid :initarg :sub :accessor sub
|
||||||
|
:documentation
|
||||||
|
"ID for the user in the authentication provider. Taken from the `:SUB'
|
||||||
|
field in the JWT when the user first logged in")
|
||||||
|
(username :col-type string :initarg :username :accessor username)
|
||||||
|
(email :col-type string :initarg :email :accessor email))
|
||||||
|
(:metaclass dao-class)
|
||||||
|
(:keys sub)
|
||||||
|
(:table-name users)
|
||||||
|
(:documentation
|
||||||
|
"Panettone users. Uses an external authentication provider."))
|
||||||
|
|
||||||
|
(deftable (user "users")
|
||||||
|
(!dao-def))
|
||||||
|
|
||||||
(defclass user-settings ()
|
(defclass user-settings ()
|
||||||
((user-dn :col-type string :initarg :user-dn :accessor user-dn)
|
((user-dn :col-type string :initarg :user-dn :accessor user-dn)
|
||||||
(enable-email-notifications
|
(enable-email-notifications
|
||||||
|
@ -219,6 +235,17 @@ its new value will be formatted using ~A into NEW-VALUE"))
|
||||||
(:documentation "Migration scripts that have been run on the database"))
|
(:documentation "Migration scripts that have been run on the database"))
|
||||||
(deftable migration (!dao-def))
|
(deftable migration (!dao-def))
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; Utils
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(defun create-table-if-not-exists (name)
|
||||||
|
" Takes the name of a dao-class and creates the table identified by symbol by
|
||||||
|
executing all forms in its definition as found in the *tables* list, if it does
|
||||||
|
not already exist."
|
||||||
|
(unless (table-exists-p (dao-table-name name))
|
||||||
|
(create-table name)))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Migrations
|
;;; Migrations
|
||||||
;;;
|
;;;
|
||||||
|
@ -571,8 +598,9 @@ explicitly subscribing to / unsubscribing from individual issues."
|
||||||
|
|
||||||
;; Creating new migrations
|
;; Creating new migrations
|
||||||
(setq *migrations-dir* (merge-pathnames "migrations/"))
|
(setq *migrations-dir* (merge-pathnames "migrations/"))
|
||||||
(generate-migration "add-issue-tsv"
|
(generate-migration "create-users-table"
|
||||||
:documentation "Add tsvector for full-text search of issues")
|
:documentation "Add a table to store information about users")
|
||||||
|
(load-migrations)
|
||||||
|
|
||||||
;; Running migrations
|
;; Running migrations
|
||||||
(with-connection *pg-spec*
|
(with-connection *pg-spec*
|
||||||
|
|
|
@ -42,6 +42,11 @@
|
||||||
:migrate
|
:migrate
|
||||||
:*pg-spec*
|
:*pg-spec*
|
||||||
|
|
||||||
|
:create-table-if-not-exists
|
||||||
|
|
||||||
|
:user
|
||||||
|
:sub :username :email
|
||||||
|
|
||||||
:user-settings
|
:user-settings
|
||||||
:user-dn :enable-email-notifications-p :settings-for-user
|
:user-dn :enable-email-notifications-p :settings-for-user
|
||||||
:update-user-settings :enable-email-notifications
|
:update-user-settings :enable-email-notifications
|
||||||
|
|
Loading…
Reference in a new issue