ALTER TABLE "audit_log" RENAME COLUMN "actor_id" TO "author_id";--> statement-breakpoint ALTER TABLE "audit_log" RENAME COLUMN "actor_label" TO "author";--> statement-breakpoint ALTER TABLE "audit_log" RENAME COLUMN "action" TO "text";--> statement-breakpoint ALTER TABLE "audit_log" RENAME COLUMN "metadata" TO "details";--> statement-breakpoint ALTER TABLE "audit_log" RENAME COLUMN "created_at" TO "time";--> statement-breakpoint UPDATE "audit_log" SET "details" = coalesce("details", '{}'::jsonb) || jsonb_strip_nulls(jsonb_build_object( 'target', jsonb_build_object('type', "target_type", 'id', "target_id"), 'scope', "scope", 'version', "resulting_version" ));--> statement-breakpoint ALTER TABLE "audit_log" ALTER COLUMN "author_id" DROP NOT NULL;--> statement-breakpoint ALTER TABLE "audit_log" ALTER COLUMN "author" DROP NOT NULL;--> statement-breakpoint ALTER TABLE "audit_log" ALTER COLUMN "text" TYPE text;--> statement-breakpoint ALTER TABLE "audit_log" ALTER COLUMN "details" DROP NOT NULL;--> statement-breakpoint DROP INDEX "audit_log_created_idx";--> statement-breakpoint DROP INDEX "audit_log_actor_created_idx";--> statement-breakpoint DROP INDEX "audit_log_target_created_idx";--> statement-breakpoint DROP INDEX "audit_log_action_created_idx";--> statement-breakpoint CREATE INDEX "audit_log_time_idx" ON "audit_log" USING btree ("time","id");--> statement-breakpoint CREATE INDEX "audit_log_author_time_idx" ON "audit_log" USING btree ("author_id","time");--> statement-breakpoint ALTER TABLE "audit_log" DROP COLUMN "target_type";--> statement-breakpoint ALTER TABLE "audit_log" DROP COLUMN "target_id";--> statement-breakpoint ALTER TABLE "audit_log" DROP COLUMN "scope";--> statement-breakpoint ALTER TABLE "audit_log" DROP COLUMN "resulting_version";