Revise user data cleanup logic to ensure proper cascading deletion of user-related database rows and S3 objects, including shared document and preview artifacts. Introduce explicit checks for last ownership before removing shared resources. Add TTS segment cache and audio cleanup to document and user deletion flows. Expand user data export to include TTS segment entries and audio, job events, document settings, and linked auth sessions. Update schema with ON DELETE CASCADE for userTtsChars and userJobEvents. Add new migration scripts and comprehensive unit tests for cleanup and export scenarios.
8 lines
668 B
SQL
8 lines
668 B
SQL
DELETE FROM "user_job_events" WHERE NOT EXISTS (
|
|
SELECT 1 FROM "user" WHERE "user"."id" = "user_job_events"."user_id"
|
|
);--> statement-breakpoint
|
|
DELETE FROM "user_tts_chars" WHERE NOT EXISTS (
|
|
SELECT 1 FROM "user" WHERE "user"."id" = "user_tts_chars"."user_id"
|
|
);--> statement-breakpoint
|
|
ALTER TABLE "user_job_events" ADD CONSTRAINT "user_job_events_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "user_tts_chars" ADD CONSTRAINT "user_tts_chars_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|