Skip to content

Commit

Permalink
chore(migrations): add migration to delete unused audits and update a…
Browse files Browse the repository at this point in the history
…udit enum

chore(migrations): add migration to delete unused audits

chore(migrations): add migration to update audit enum
  • Loading branch information
RichardBray committed Aug 16, 2023
1 parent 25e066d commit 1dd6326
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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';
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";

0 comments on commit 1dd6326

Please sign in to comment.