Skip to content

Commit b5f9576

Browse files
authored
schema generation files (#326)
* Retention policy schema/types * schema generate
1 parent 85000ad commit b5f9576

3 files changed

Lines changed: 1782 additions & 173 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CREATE TABLE "email_legal_holds" (
2+
"email_id" uuid NOT NULL,
3+
"legal_hold_id" uuid NOT NULL,
4+
CONSTRAINT "email_legal_holds_email_id_legal_hold_id_pk" PRIMARY KEY("email_id","legal_hold_id")
5+
);
6+
--> statement-breakpoint
7+
CREATE TABLE "email_retention_labels" (
8+
"email_id" uuid NOT NULL,
9+
"label_id" uuid NOT NULL,
10+
"applied_at" timestamp with time zone DEFAULT now() NOT NULL,
11+
"applied_by_user_id" uuid,
12+
CONSTRAINT "email_retention_labels_email_id_label_id_pk" PRIMARY KEY("email_id","label_id")
13+
);
14+
--> statement-breakpoint
15+
CREATE TABLE "retention_events" (
16+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
17+
"event_name" varchar(255) NOT NULL,
18+
"event_type" varchar(100) NOT NULL,
19+
"event_timestamp" timestamp with time zone NOT NULL,
20+
"target_criteria" jsonb NOT NULL,
21+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
22+
);
23+
--> statement-breakpoint
24+
CREATE TABLE "retention_labels" (
25+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
26+
"name" varchar(255) NOT NULL,
27+
"retention_period_days" integer NOT NULL,
28+
"description" text,
29+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
30+
);
31+
--> statement-breakpoint
32+
ALTER TABLE "legal_holds" DROP CONSTRAINT "legal_holds_custodian_id_custodians_id_fk";
33+
--> statement-breakpoint
34+
ALTER TABLE "legal_holds" DROP CONSTRAINT "legal_holds_case_id_ediscovery_cases_id_fk";
35+
--> statement-breakpoint
36+
ALTER TABLE "legal_holds" ALTER COLUMN "case_id" DROP NOT NULL;--> statement-breakpoint
37+
ALTER TABLE "legal_holds" ADD COLUMN "name" varchar(255) NOT NULL;--> statement-breakpoint
38+
ALTER TABLE "legal_holds" ADD COLUMN "is_active" boolean DEFAULT true NOT NULL;--> statement-breakpoint
39+
ALTER TABLE "legal_holds" ADD COLUMN "created_at" timestamp with time zone DEFAULT now() NOT NULL;--> statement-breakpoint
40+
ALTER TABLE "legal_holds" ADD COLUMN "updated_at" timestamp with time zone DEFAULT now() NOT NULL;--> statement-breakpoint
41+
ALTER TABLE "email_legal_holds" ADD CONSTRAINT "email_legal_holds_email_id_archived_emails_id_fk" FOREIGN KEY ("email_id") REFERENCES "public"."archived_emails"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
42+
ALTER TABLE "email_legal_holds" ADD CONSTRAINT "email_legal_holds_legal_hold_id_legal_holds_id_fk" FOREIGN KEY ("legal_hold_id") REFERENCES "public"."legal_holds"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
43+
ALTER TABLE "email_retention_labels" ADD CONSTRAINT "email_retention_labels_email_id_archived_emails_id_fk" FOREIGN KEY ("email_id") REFERENCES "public"."archived_emails"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
44+
ALTER TABLE "email_retention_labels" ADD CONSTRAINT "email_retention_labels_label_id_retention_labels_id_fk" FOREIGN KEY ("label_id") REFERENCES "public"."retention_labels"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
45+
ALTER TABLE "email_retention_labels" ADD CONSTRAINT "email_retention_labels_applied_by_user_id_users_id_fk" FOREIGN KEY ("applied_by_user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
46+
ALTER TABLE "legal_holds" ADD CONSTRAINT "legal_holds_case_id_ediscovery_cases_id_fk" FOREIGN KEY ("case_id") REFERENCES "public"."ediscovery_cases"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
47+
ALTER TABLE "legal_holds" DROP COLUMN "custodian_id";--> statement-breakpoint
48+
ALTER TABLE "legal_holds" DROP COLUMN "hold_criteria";--> statement-breakpoint
49+
ALTER TABLE "legal_holds" DROP COLUMN "applied_by_identifier";--> statement-breakpoint
50+
ALTER TABLE "legal_holds" DROP COLUMN "applied_at";--> statement-breakpoint
51+
ALTER TABLE "legal_holds" DROP COLUMN "removed_at";

0 commit comments

Comments
 (0)