Files
alla-allaos-fullstack/drizzle/0006_massive_scalphunter.sql
phaichayon ab56852c47 task-ep.1.6
2026-07-13 16:29:40 +07:00

46 lines
2.5 KiB
SQL

CREATE TABLE "crm_calendar_projection" (
"id" text PRIMARY KEY NOT NULL,
"organization_id" text NOT NULL,
"branch_id" text,
"product_type" text,
"customer_id" text,
"lead_id" text,
"opportunity_id" text,
"quotation_id" text,
"approval_id" text,
"activity_id" text,
"owner_id" text,
"assignee_id" text,
"event_id" text NOT NULL,
"entity_type" text NOT NULL,
"entity_id" text NOT NULL,
"title" text NOT NULL,
"summary" text,
"location" text,
"start_at" timestamp with time zone NOT NULL,
"end_at" timestamp with time zone NOT NULL,
"timezone" text DEFAULT 'Asia/Bangkok' NOT NULL,
"priority" text DEFAULT 'normal' NOT NULL,
"category" text NOT NULL,
"activity_type" text,
"editable" boolean DEFAULT false NOT NULL,
"milestone" boolean DEFAULT false NOT NULL,
"overdue" boolean DEFAULT false NOT NULL,
"hot_project" boolean DEFAULT false NOT NULL,
"all_day" boolean DEFAULT false NOT NULL,
"visibility" jsonb NOT NULL,
"metadata" jsonb,
"source_event" jsonb NOT NULL,
"source_projection_version" integer DEFAULT 1 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX "crm_calendar_projection_event_version_idx" ON "crm_calendar_projection" USING btree ("event_id","source_projection_version");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_org_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_org_assignee_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","assignee_id","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_org_owner_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","owner_id","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_org_branch_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","branch_id","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_org_category_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","category","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_customer_start_idx" ON "crm_calendar_projection" USING btree ("organization_id","customer_id","start_at");--> statement-breakpoint
CREATE INDEX "crm_calendar_projection_activity_event_idx" ON "crm_calendar_projection" USING btree ("organization_id","activity_id","event_id");