CREATE TABLE "crm_activities" (
	"id" text PRIMARY KEY NOT NULL,
	"organization_id" text NOT NULL,
	"primary_entity_type" text NOT NULL,
	"primary_entity_id" text,
	"primary_record_label" text,
	"related_records" jsonb DEFAULT '[]'::jsonb NOT NULL,
	"customer_id" text,
	"contact_id" text,
	"lead_id" text,
	"opportunity_id" text,
	"quotation_id" text,
	"activity_type" text NOT NULL,
	"subject" text NOT NULL,
	"description" text,
	"owner_id" text NOT NULL,
	"assigned_to_id" text,
	"scheduled_start_at" timestamp with time zone,
	"scheduled_end_at" timestamp with time zone,
	"due_at" timestamp with time zone,
	"completed_at" timestamp with time zone,
	"cancelled_at" timestamp with time zone,
	"skipped_at" timestamp with time zone,
	"status" text NOT NULL,
	"priority" text NOT NULL,
	"outcome_summary" text,
	"cancellation_reason" text,
	"skip_reason" text,
	"next_action" text,
	"branch_id" text,
	"product_type" text,
	"is_internal_only" boolean DEFAULT false NOT NULL,
	"is_pricing_sensitive" boolean DEFAULT false NOT NULL,
	"parent_activity_id" text,
	"metadata" jsonb,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	"deleted_at" timestamp with time zone,
	"created_by" text NOT NULL,
	"updated_by" text NOT NULL
);
