feat(web/panettone): Add a system for database migrations

Add a system for writing, running, and tracking database
migrations (changes to the database schema) over time, inspired by but
significantly simpler than postmodern-passenger-pigeon.

Migrations can be generated by
running (PANETTONE.MODEL:GENERATE-MIGRATION "name"), and are numerically
ordered lisp files that define (at least) a function called UP, which
runs the migration. The migrations that have been run against the
database are tracked in the `migrations` table, and when the
`(PANETTONE.MODEL:MIGRATE)` function is called (as it is on startup),
all migrations that have not yet been run are run within a transaction.

This includes one migration `1-init-schema.lisp`, which migrates the
database (idempotently) to the current state of the schema.

Change-Id: Id243a47763abea649784b12f25a6d05c2267381c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11253
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Aspen Smith 2024-03-24 10:32:15 -04:00 committed by aspen
parent d5f57ac6e6
commit a1a29f7c0b
5 changed files with 228 additions and 37 deletions

View file

@ -36,16 +36,16 @@
(:import-from :alexandria :if-let :when-let :define-constant)
(:export
:prepare-db-connections
:ddl/init
:migrate
:*pg-spec*
:user-settings
:user-dn :enable-email-notifications-p :settings-for-user
:update-user-settings :enable-email-notifications
:issue :issue-comment :issue-event
:issue :issue-comment :issue-event :migration
:id :subject :body :author-dn :issue-id :status :created-at :acting-user-dn
:field :previous-value :new-value
:field :previous-value :new-value :+issue-statuses+
:get-issue :issue-exists-p :list-issues :create-issue :set-issue-status
:update-issue :delete-issue :issue-not-found :not-found-id