Lots of changes to the cmap stuff
This commit is contained in:
+41
-1
@@ -20,7 +20,7 @@
|
||||
;; Supporting functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define current-schema-version 11)
|
||||
(define current-schema-version 12)
|
||||
|
||||
(define schema-1-statements
|
||||
(list
|
||||
@@ -384,6 +384,43 @@ SQL
|
||||
)
|
||||
(record-schema-version! db 11))
|
||||
|
||||
(define (migrate-11->12! db)
|
||||
;; Older clients stored both automatic and explicit saves as `edit`. Preserve
|
||||
;; the explicit saves, discard redundant autosave copies, and enforce the new
|
||||
;; five-item manual history limit per CMap.
|
||||
(query-exec db
|
||||
#<<SQL
|
||||
UPDATE concept_map_versions
|
||||
SET action = 'manual'
|
||||
WHERE action = 'edit'
|
||||
AND summary IN ('Manual save', 'Handmatig opgeslagen')
|
||||
SQL
|
||||
)
|
||||
(query-exec db
|
||||
#<<SQL
|
||||
DELETE FROM concept_map_versions
|
||||
WHERE action = 'edit'
|
||||
AND summary IN ('Automatic save', 'Automatisch opgeslagen')
|
||||
SQL
|
||||
)
|
||||
(query-exec db
|
||||
#<<SQL
|
||||
WITH ranked AS (
|
||||
SELECT id,
|
||||
row_number() OVER (
|
||||
PARTITION BY concept_map_id
|
||||
ORDER BY version DESC
|
||||
) AS position
|
||||
FROM concept_map_versions
|
||||
WHERE action = 'manual'
|
||||
)
|
||||
DELETE FROM concept_map_versions cmv
|
||||
USING ranked
|
||||
WHERE cmv.id = ranked.id AND ranked.position > 5
|
||||
SQL
|
||||
)
|
||||
(record-schema-version! db 12))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; goal : Bring a racket-wiki PostgreSQL database to the current schema.
|
||||
; pre : db is a writable PostgreSQL connection and config identifies the
|
||||
@@ -428,6 +465,9 @@ SQL
|
||||
(define after-user-profiles (database-schema-version db))
|
||||
(when (= after-user-profiles 10)
|
||||
(migrate-10->11! db))
|
||||
(define after-concept-map-history (database-schema-version db))
|
||||
(when (= after-concept-map-history 11)
|
||||
(migrate-11->12! db))
|
||||
(define resulting-version (database-schema-version db))
|
||||
(when (> resulting-version current-schema-version)
|
||||
(error 'migrate-database!
|
||||
|
||||
Reference in New Issue
Block a user