-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(migrations): add migration to delete unused audits and update a…
…udit enum chore(migrations): add migration to delete unused audits chore(migrations): add migration to update audit enum
- Loading branch information
1 parent
25e066d
commit 1dd6326
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
src/server/models/db/migrations/20230717140537_delete_unused_audits/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- Delete all lstItem audit events. | ||
DELETE FROM "Audit" | ||
WHERE type = 'listItem'; |
25 changes: 25 additions & 0 deletions
25
src/server/models/db/migrations/20230717145215_update_audit_enum/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Warnings: | ||
- The values [OUT_WITH_PROVIDER,EDITED,REVIEWED,UNPUBLISHED,PUBLISHED,PINNED,UNPINNED] on the enum `AuditEvent` will be removed. If these variants are still used in the database, this will fail. | ||
*/ | ||
-- AlterEnum | ||
-- 1. Rename the enum type you want to change | ||
ALTER TYPE "AuditEvent" RENAME TO "_AuditEvent"; | ||
|
||
-- 2. Create the new enum type | ||
CREATE TYPE "AuditEvent" AS ENUM ('NEW', 'ANNUAL_REVIEW', 'DELETED', 'UNDEFINED', 'REMINDER', 'ANALYTICS', 'LIST_EDIT'); | ||
|
||
-- 3. Rename the column(s) which use the old enum type | ||
ALTER TABLE "Audit" RENAME COLUMN "auditEvent" TO "_auditEvent"; | ||
|
||
-- 4. Add new column of the new type | ||
ALTER TABLE "Audit" ADD "auditEvent" "AuditEvent" NOT NULL DEFAULT 'NEW'; | ||
|
||
-- 5. Copy values to the new column | ||
UPDATE "Audit" SET "auditEvent" = "_auditEvent"::text::"AuditEvent"; | ||
|
||
-- 6. Remove the old column and type | ||
ALTER TABLE "Audit" DROP COLUMN "_auditEvent"; | ||
DROP TYPE "_AuditEvent"; |