sla show
This commit is contained in:
@@ -1,3 +1,106 @@
|
||||
CREATE TABLE "app_notification_deliveries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"notification_id" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"recipient_address" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"attempt_count" integer DEFAULT 0 NOT NULL,
|
||||
"last_error" text,
|
||||
"sent_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_dispatches" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_id" text NOT NULL,
|
||||
"template_id" text,
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"provider_key" text NOT NULL,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"recipient_to" jsonb NOT NULL,
|
||||
"recipient_cc" jsonb,
|
||||
"recipient_bcc" jsonb,
|
||||
"reply_to" text,
|
||||
"subject" text NOT NULL,
|
||||
"body_text" text NOT NULL,
|
||||
"body_html" text,
|
||||
"attachments" jsonb,
|
||||
"recipient_user_id" text,
|
||||
"recipient_address" text,
|
||||
"requested_by" text NOT NULL,
|
||||
"metadata" jsonb,
|
||||
"last_error" text,
|
||||
"retry_count" integer DEFAULT 0 NOT NULL,
|
||||
"max_retry_count" integer DEFAULT 3 NOT NULL,
|
||||
"last_attempt_at" timestamp with time zone,
|
||||
"sent_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_events" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_type" text NOT NULL,
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"actor_user_id" text,
|
||||
"payload" jsonb,
|
||||
"dedupe_key" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"last_error" text,
|
||||
"published_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"processed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_templates" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_type" text NOT NULL,
|
||||
"code" text DEFAULT '' NOT NULL,
|
||||
"name" text DEFAULT '' NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"subject_template" text,
|
||||
"title_template" text NOT NULL,
|
||||
"body_template" text NOT NULL,
|
||||
"body_format" text DEFAULT 'plain' NOT NULL,
|
||||
"link_template" text,
|
||||
"language" text DEFAULT 'th' NOT NULL,
|
||||
"variables" jsonb,
|
||||
"version" integer DEFAULT 1 NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notifications" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"recipient_user_id" text NOT NULL,
|
||||
"event_id" text NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"body" text NOT NULL,
|
||||
"link_url" text,
|
||||
"severity" text DEFAULT 'info' NOT NULL,
|
||||
"status" text DEFAULT 'unread' NOT NULL,
|
||||
"read_at" timestamp with time zone,
|
||||
"archived_at" timestamp with time zone,
|
||||
"metadata" jsonb,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_actions" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
@@ -12,6 +115,60 @@ CREATE TABLE "crm_approval_actions" (
|
||||
"deleted_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_escalation_policies" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"step_number" integer NOT NULL,
|
||||
"trigger_after_hours" integer NOT NULL,
|
||||
"target_type" text NOT NULL,
|
||||
"target_value" text,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_matrices" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"entity_type" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"branch_id" text,
|
||||
"product_type" text,
|
||||
"min_amount" double precision,
|
||||
"max_amount" double precision,
|
||||
"currency" text,
|
||||
"priority" integer DEFAULT 100 NOT NULL,
|
||||
"is_default" boolean DEFAULT false NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"description" text,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_reminder_policies" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"step_number" integer NOT NULL,
|
||||
"sla_hours" integer DEFAULT 24 NOT NULL,
|
||||
"reminder_offsets_hours" integer[] DEFAULT '{}' NOT NULL,
|
||||
"calendar_mode" text DEFAULT 'calendar_days' NOT NULL,
|
||||
"timeout_action" text DEFAULT 'none' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_requests" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
@@ -19,6 +176,7 @@ CREATE TABLE "crm_approval_requests" (
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"current_step" integer DEFAULT 1 NOT NULL,
|
||||
"current_step_started_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"status" text NOT NULL,
|
||||
"requested_by" text NOT NULL,
|
||||
"requested_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
@@ -35,7 +193,11 @@ CREATE TABLE "crm_approval_steps" (
|
||||
"step_number" integer NOT NULL,
|
||||
"role_code" text NOT NULL,
|
||||
"role_name" text NOT NULL,
|
||||
"approval_mode" text DEFAULT 'sequential' NOT NULL,
|
||||
"is_required" boolean DEFAULT true NOT NULL,
|
||||
"sla_hours" integer DEFAULT 24 NOT NULL,
|
||||
"calendar_mode" text DEFAULT 'calendar_days' NOT NULL,
|
||||
"timeout_action" text DEFAULT 'none' NOT NULL,
|
||||
"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
|
||||
@@ -47,7 +209,11 @@ CREATE TABLE "crm_approval_workflows" (
|
||||
"code" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"entity_type" text NOT NULL,
|
||||
"description" text,
|
||||
"is_system" boolean DEFAULT false NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"created_by" text NOT NULL,
|
||||
"updated_by" text NOT NULL,
|
||||
"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
|
||||
@@ -164,6 +330,49 @@ CREATE TABLE "crm_document_artifacts" (
|
||||
"deleted_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_libraries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"code" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"document_type" text NOT NULL,
|
||||
"description" text,
|
||||
"brand" text NOT NULL,
|
||||
"language" text NOT NULL,
|
||||
"product_type" text NOT NULL,
|
||||
"status" text DEFAULT 'active' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_library_versions" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"library_id" text NOT NULL,
|
||||
"version" text NOT NULL,
|
||||
"file_name" text NOT NULL,
|
||||
"storage_provider" text NOT NULL,
|
||||
"storage_key" text NOT NULL,
|
||||
"mime_type" text NOT NULL,
|
||||
"file_size" integer NOT NULL,
|
||||
"checksum" text NOT NULL,
|
||||
"page_count" integer NOT NULL,
|
||||
"status" text DEFAULT 'draft' NOT NULL,
|
||||
"is_active" boolean DEFAULT false NOT NULL,
|
||||
"published_at" timestamp with time zone,
|
||||
"published_by" text,
|
||||
"archived_at" timestamp with time zone,
|
||||
"archived_by" text,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_template_mappings" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
@@ -201,6 +410,7 @@ CREATE TABLE "crm_document_template_versions" (
|
||||
"version" text NOT NULL,
|
||||
"file_path" text,
|
||||
"schema_json" jsonb NOT NULL,
|
||||
"metadata_json" jsonb,
|
||||
"preview_image_url" text,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
@@ -270,6 +480,7 @@ CREATE TABLE "crm_opportunities" (
|
||||
"project_location" text,
|
||||
"product_type" text NOT NULL,
|
||||
"status" text NOT NULL,
|
||||
"outcome_status" text DEFAULT 'open' NOT NULL,
|
||||
"priority" text NOT NULL,
|
||||
"lead_channel" text,
|
||||
"estimated_value" double precision,
|
||||
@@ -281,6 +492,7 @@ CREATE TABLE "crm_opportunities" (
|
||||
"is_hot_project" boolean DEFAULT false NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"pipeline_stage" text DEFAULT 'lead' NOT NULL,
|
||||
"closed_at" timestamp with time zone,
|
||||
"closed_won_at" timestamp with time zone,
|
||||
"closed_lost_at" timestamp with time zone,
|
||||
"closed_by_user_id" text,
|
||||
@@ -289,8 +501,11 @@ CREATE TABLE "crm_opportunities" (
|
||||
"po_amount" double precision,
|
||||
"po_currency" text,
|
||||
"lost_reason" text,
|
||||
"lost_detail" text,
|
||||
"lost_competitor" text,
|
||||
"lost_remark" text,
|
||||
"cancel_reason" text,
|
||||
"no_quotation_reason" text,
|
||||
"assigned_to_user_id" text,
|
||||
"assigned_at" timestamp with time zone,
|
||||
"assigned_by" text,
|
||||
@@ -549,11 +764,14 @@ CREATE TABLE "document_sequences" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"branch_id" text DEFAULT '' NOT NULL,
|
||||
"product_type" text DEFAULT 'all' NOT NULL,
|
||||
"document_type" text NOT NULL,
|
||||
"prefix" text NOT NULL,
|
||||
"period" text NOT NULL,
|
||||
"current_number" integer DEFAULT 0 NOT NULL,
|
||||
"padding_length" integer DEFAULT 3 NOT NULL,
|
||||
"format" text DEFAULT '{prefix}{period}-{running}' NOT NULL,
|
||||
"reset_policy" text DEFAULT 'period' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
@@ -637,10 +855,17 @@ CREATE TABLE "users" (
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notification_dispatches_org_event_channel_recipient_idx" ON "app_notification_dispatches" USING btree ("organization_id","event_id","channel","recipient_address");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notification_events_org_dedupe_idx" ON "app_notification_events" USING btree ("organization_id","dedupe_key");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notification_templates_org_event_channel_idx" ON "app_notification_templates" USING btree ("organization_id","event_type","channel");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notifications_recipient_event_idx" ON "app_notifications" USING btree ("recipient_user_id","event_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_approval_reminder_policies_workflow_step_idx" ON "crm_approval_reminder_policies" USING btree ("workflow_id","step_number");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_approval_steps_workflow_step_idx" ON "crm_approval_steps" USING btree ("workflow_id","step_number");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_approval_workflows_org_code_idx" ON "crm_approval_workflows" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_contact_shares_org_contact_shared_user_idx" ON "crm_contact_shares" USING btree ("organization_id","contact_id","shared_to_user_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_customers_org_code_idx" ON "crm_customers" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_libraries_org_code_idx" ON "crm_document_libraries" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_library_versions_library_version_idx" ON "crm_document_library_versions" USING btree ("library_id","version");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_template_mappings_version_placeholder_idx" ON "crm_document_template_mappings" USING btree ("template_version_id","placeholder_key");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_template_table_columns_mapping_name_idx" ON "crm_document_template_table_columns" USING btree ("mapping_id","column_name");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_template_versions_template_version_idx" ON "crm_document_template_versions" USING btree ("template_id","version");--> statement-breakpoint
|
||||
@@ -651,7 +876,7 @@ CREATE UNIQUE INDEX "crm_quotations_org_code_idx" ON "crm_quotations" USING btre
|
||||
CREATE UNIQUE INDEX "crm_report_definitions_org_code_idx" ON "crm_report_definitions" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_role_profiles_org_code_idx" ON "crm_role_profiles" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_user_role_assignments_org_user_role_idx" ON "crm_user_role_assignments" USING btree ("organization_id","user_id","role_profile_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "document_sequences_org_doc_period_branch_idx" ON "document_sequences" USING btree ("organization_id","document_type","period","branch_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "document_sequences_org_branch_product_doc_period_idx" ON "document_sequences" USING btree ("organization_id","branch_id","product_type","document_type","period");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "ms_options_org_category_code_idx" ON "ms_options" USING btree ("organization_id","category","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "organizations_slug_idx" ON "organizations" USING btree ("slug");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "users_email_idx" ON "users" USING btree ("email");
|
||||
@@ -1,5 +0,0 @@
|
||||
ALTER TABLE "crm_opportunities" ADD COLUMN "outcome_status" text DEFAULT 'open' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "crm_opportunities" ADD COLUMN "closed_at" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "crm_opportunities" ADD COLUMN "lost_detail" text;--> statement-breakpoint
|
||||
ALTER TABLE "crm_opportunities" ADD COLUMN "cancel_reason" text;--> statement-breakpoint
|
||||
ALTER TABLE "crm_opportunities" ADD COLUMN "no_quotation_reason" text;
|
||||
@@ -1,20 +0,0 @@
|
||||
CREATE TABLE "crm_approval_matrices" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"entity_type" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"branch_id" text,
|
||||
"product_type" text,
|
||||
"min_amount" double precision,
|
||||
"max_amount" double precision,
|
||||
"currency" text,
|
||||
"priority" integer DEFAULT 100 NOT NULL,
|
||||
"is_default" boolean DEFAULT false NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"description" text,
|
||||
"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
|
||||
);
|
||||
@@ -1,14 +0,0 @@
|
||||
ALTER TABLE "crm_approval_workflows"
|
||||
ADD COLUMN "description" text;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_workflows"
|
||||
ADD COLUMN "is_system" boolean DEFAULT false NOT NULL;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_workflows"
|
||||
ADD COLUMN "created_by" text NOT NULL DEFAULT '';
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_workflows"
|
||||
ADD COLUMN "updated_by" text NOT NULL DEFAULT '';
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_steps"
|
||||
ADD COLUMN "approval_mode" text DEFAULT 'sequential' NOT NULL;
|
||||
@@ -1,73 +0,0 @@
|
||||
CREATE TABLE "app_notification_deliveries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"notification_id" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"recipient_address" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"attempt_count" integer DEFAULT 0 NOT NULL,
|
||||
"last_error" text,
|
||||
"sent_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_events" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_type" text NOT NULL,
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"actor_user_id" text,
|
||||
"payload" jsonb,
|
||||
"dedupe_key" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"last_error" text,
|
||||
"published_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"processed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_templates" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_type" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"title_template" text NOT NULL,
|
||||
"body_template" text NOT NULL,
|
||||
"link_template" text,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notifications" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"recipient_user_id" text NOT NULL,
|
||||
"event_id" text NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"body" text NOT NULL,
|
||||
"link_url" text,
|
||||
"severity" text DEFAULT 'info' NOT NULL,
|
||||
"status" text DEFAULT 'unread' NOT NULL,
|
||||
"read_at" timestamp with time zone,
|
||||
"archived_at" timestamp with time zone,
|
||||
"metadata" jsonb,
|
||||
"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 "app_notification_events_org_dedupe_idx"
|
||||
ON "app_notification_events" USING btree ("organization_id", "dedupe_key");
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notification_templates_org_event_channel_idx"
|
||||
ON "app_notification_templates" USING btree ("organization_id", "event_type", "channel");
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notifications_recipient_event_idx"
|
||||
ON "app_notifications" USING btree ("recipient_user_id", "event_id");
|
||||
@@ -1,38 +0,0 @@
|
||||
CREATE TABLE "crm_approval_escalation_policies" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"step_number" integer NOT NULL,
|
||||
"trigger_after_hours" integer NOT NULL,
|
||||
"target_type" text NOT NULL,
|
||||
"target_value" text,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_approval_reminder_policies" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"workflow_id" text NOT NULL,
|
||||
"step_number" integer NOT NULL,
|
||||
"sla_hours" integer DEFAULT 24 NOT NULL,
|
||||
"reminder_offsets_hours" integer[] DEFAULT '{}' NOT NULL,
|
||||
"calendar_mode" text DEFAULT 'calendar_days' NOT NULL,
|
||||
"timeout_action" text DEFAULT 'none' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_requests" ADD COLUMN "current_step_started_at" timestamp with time zone DEFAULT now() NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_steps" ADD COLUMN "sla_hours" integer DEFAULT 24 NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_steps" ADD COLUMN "calendar_mode" text DEFAULT 'calendar_days' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "crm_approval_steps" ADD COLUMN "timeout_action" text DEFAULT 'none' NOT NULL;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_approval_reminder_policies_workflow_step_idx" ON "crm_approval_reminder_policies" USING btree ("workflow_id","step_number");
|
||||
@@ -1,11 +0,0 @@
|
||||
ALTER TABLE "crm_document_template_versions" ADD COLUMN "metadata_json" jsonb;
|
||||
--> statement-breakpoint
|
||||
UPDATE "crm_document_template_versions"
|
||||
SET
|
||||
"metadata_json" = COALESCE("metadata_json", "schema_json" -> '__templateManagement'),
|
||||
"schema_json" = CASE
|
||||
WHEN "schema_json" ? '__templateManagement'
|
||||
THEN "schema_json" - '__templateManagement'
|
||||
ELSE "schema_json"
|
||||
END
|
||||
WHERE "schema_json" ? '__templateManagement';
|
||||
@@ -1,50 +0,0 @@
|
||||
CREATE TABLE "crm_document_libraries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"code" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"document_type" text NOT NULL,
|
||||
"description" text,
|
||||
"brand" text NOT NULL,
|
||||
"language" text NOT NULL,
|
||||
"product_type" text NOT NULL,
|
||||
"status" text DEFAULT 'active' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_libraries_org_code_idx" ON "crm_document_libraries" USING btree ("organization_id","code");
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_library_versions" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"library_id" text NOT NULL,
|
||||
"version" text NOT NULL,
|
||||
"file_name" text NOT NULL,
|
||||
"storage_provider" text NOT NULL,
|
||||
"storage_key" text NOT NULL,
|
||||
"mime_type" text NOT NULL,
|
||||
"file_size" integer NOT NULL,
|
||||
"checksum" text NOT NULL,
|
||||
"page_count" integer NOT NULL,
|
||||
"status" text DEFAULT 'draft' NOT NULL,
|
||||
"is_active" boolean DEFAULT false NOT NULL,
|
||||
"published_at" timestamp with time zone,
|
||||
"published_by" text,
|
||||
"archived_at" timestamp with time zone,
|
||||
"archived_by" text,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_library_versions_library_version_idx" ON "crm_document_library_versions" USING btree ("library_id","version");
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_library_versions_active_library_idx"
|
||||
ON "crm_document_library_versions" USING btree ("library_id")
|
||||
WHERE "is_active" = true AND "deleted_at" IS NULL;
|
||||
@@ -1,28 +0,0 @@
|
||||
ALTER TABLE "document_sequences"
|
||||
ADD COLUMN "product_type" text DEFAULT 'all' NOT NULL;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "document_sequences"
|
||||
ADD COLUMN "format" text DEFAULT '{prefix}{period}-{running}' NOT NULL;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "document_sequences"
|
||||
ADD COLUMN "reset_policy" text DEFAULT 'period' NOT NULL;
|
||||
--> statement-breakpoint
|
||||
UPDATE "document_sequences"
|
||||
SET
|
||||
"product_type" = CASE
|
||||
WHEN "document_type" = 'quotation' THEN 'legacy'
|
||||
ELSE 'all'
|
||||
END,
|
||||
"format" = '{prefix}{period}-{running}',
|
||||
"reset_policy" = 'period';
|
||||
--> statement-breakpoint
|
||||
DROP INDEX "document_sequences_org_doc_period_branch_idx";
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "document_sequences_org_branch_product_doc_period_idx"
|
||||
ON "document_sequences" USING btree (
|
||||
"organization_id",
|
||||
"branch_id",
|
||||
"product_type",
|
||||
"document_type",
|
||||
"period"
|
||||
);
|
||||
@@ -1,60 +0,0 @@
|
||||
ALTER TABLE "app_notification_templates"
|
||||
ADD COLUMN "code" text DEFAULT '' NOT NULL,
|
||||
ADD COLUMN "name" text DEFAULT '' NOT NULL,
|
||||
ADD COLUMN "subject_template" text,
|
||||
ADD COLUMN "body_format" text DEFAULT 'plain' NOT NULL,
|
||||
ADD COLUMN "language" text DEFAULT 'th' NOT NULL,
|
||||
ADD COLUMN "variables" jsonb,
|
||||
ADD COLUMN "version" integer DEFAULT 1 NOT NULL;
|
||||
--> statement-breakpoint
|
||||
UPDATE "app_notification_templates"
|
||||
SET
|
||||
"code" = CASE
|
||||
WHEN "code" = '' THEN replace("event_type", '.', '_') || '_' || "channel"
|
||||
ELSE "code"
|
||||
END,
|
||||
"name" = CASE
|
||||
WHEN "name" = '' THEN "event_type" || ' (' || "channel" || ')'
|
||||
ELSE "name"
|
||||
END,
|
||||
"subject_template" = COALESCE("subject_template", "title_template"),
|
||||
"variables" = COALESCE("variables", '[]'::jsonb);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "app_notification_dispatches" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_id" text NOT NULL,
|
||||
"template_id" text,
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"provider_key" text NOT NULL,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"recipient_to" jsonb NOT NULL,
|
||||
"recipient_cc" jsonb,
|
||||
"recipient_bcc" jsonb,
|
||||
"reply_to" text,
|
||||
"subject" text NOT NULL,
|
||||
"body_text" text NOT NULL,
|
||||
"body_html" text,
|
||||
"attachments" jsonb,
|
||||
"recipient_user_id" text,
|
||||
"recipient_address" text,
|
||||
"requested_by" text NOT NULL,
|
||||
"metadata" jsonb,
|
||||
"last_error" text,
|
||||
"retry_count" integer DEFAULT 0 NOT NULL,
|
||||
"max_retry_count" integer DEFAULT 3 NOT NULL,
|
||||
"last_attempt_at" timestamp with time zone,
|
||||
"sent_at" timestamp with time zone,
|
||||
"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 "app_notification_dispatches_org_event_channel_recipient_idx"
|
||||
ON "app_notification_dispatches" USING btree (
|
||||
"organization_id",
|
||||
"event_id",
|
||||
"channel",
|
||||
"recipient_address"
|
||||
);
|
||||
@@ -1,89 +0,0 @@
|
||||
CREATE TABLE "app_notification_dispatches" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"event_id" text NOT NULL,
|
||||
"template_id" text,
|
||||
"entity_type" text NOT NULL,
|
||||
"entity_id" text NOT NULL,
|
||||
"channel" text NOT NULL,
|
||||
"provider_key" text NOT NULL,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"recipient_to" jsonb NOT NULL,
|
||||
"recipient_cc" jsonb,
|
||||
"recipient_bcc" jsonb,
|
||||
"reply_to" text,
|
||||
"subject" text NOT NULL,
|
||||
"body_text" text NOT NULL,
|
||||
"body_html" text,
|
||||
"attachments" jsonb,
|
||||
"recipient_user_id" text,
|
||||
"recipient_address" text,
|
||||
"requested_by" text NOT NULL,
|
||||
"metadata" jsonb,
|
||||
"last_error" text,
|
||||
"retry_count" integer DEFAULT 0 NOT NULL,
|
||||
"max_retry_count" integer DEFAULT 3 NOT NULL,
|
||||
"last_attempt_at" timestamp with time zone,
|
||||
"sent_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_libraries" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"code" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"document_type" text NOT NULL,
|
||||
"description" text,
|
||||
"brand" text NOT NULL,
|
||||
"language" text NOT NULL,
|
||||
"product_type" text NOT NULL,
|
||||
"status" text DEFAULT 'active' NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "crm_document_library_versions" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organization_id" text NOT NULL,
|
||||
"library_id" text NOT NULL,
|
||||
"version" text NOT NULL,
|
||||
"file_name" text NOT NULL,
|
||||
"storage_provider" text NOT NULL,
|
||||
"storage_key" text NOT NULL,
|
||||
"mime_type" text NOT NULL,
|
||||
"file_size" integer NOT NULL,
|
||||
"checksum" text NOT NULL,
|
||||
"page_count" integer NOT NULL,
|
||||
"status" text DEFAULT 'draft' NOT NULL,
|
||||
"is_active" boolean DEFAULT false NOT NULL,
|
||||
"published_at" timestamp with time zone,
|
||||
"published_by" text,
|
||||
"archived_at" timestamp with time zone,
|
||||
"archived_by" text,
|
||||
"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
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DROP INDEX "document_sequences_org_doc_period_branch_idx";--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "code" text DEFAULT '' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "name" text DEFAULT '' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "subject_template" text;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "body_format" text DEFAULT 'plain' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "language" text DEFAULT 'th' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "variables" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "app_notification_templates" ADD COLUMN "version" integer DEFAULT 1 NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "document_sequences" ADD COLUMN "product_type" text DEFAULT 'all' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "document_sequences" ADD COLUMN "format" text DEFAULT '{prefix}{period}-{running}' NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "document_sequences" ADD COLUMN "reset_policy" text DEFAULT 'period' NOT NULL;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "app_notification_dispatches_org_event_channel_recipient_idx" ON "app_notification_dispatches" USING btree ("organization_id","event_id","channel","recipient_address");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_libraries_org_code_idx" ON "crm_document_libraries" USING btree ("organization_id","code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "crm_document_library_versions_library_version_idx" ON "crm_document_library_versions" USING btree ("library_id","version");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "document_sequences_org_branch_product_doc_period_idx" ON "document_sequences" USING btree ("organization_id","branch_id","product_type","document_type","period");
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -5,71 +5,8 @@
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1782359607850,
|
||||
"tag": "0000_hard_butterfly",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1782381033930,
|
||||
"tag": "0001_lazy_otto_octavius",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "7",
|
||||
"when": 1782604800000,
|
||||
"tag": "0002_calm_approval_matrix",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "7",
|
||||
"when": 1782691200000,
|
||||
"tag": "0003_workflow_builder_foundation",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "7",
|
||||
"when": 1782455991734,
|
||||
"tag": "0004_unusual_hairball",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "7",
|
||||
"when": 1782464526434,
|
||||
"tag": "0005_furry_maelstrom",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "7",
|
||||
"when": 1782749787685,
|
||||
"tag": "0006_lazy_shiver_man",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1782910000000,
|
||||
"tag": "0007_document_library_foundation",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "7",
|
||||
"when": 1782913600000,
|
||||
"tag": "0008_document_sequence_scope_refactor",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"version": "7",
|
||||
"when": 1782815675836,
|
||||
"tag": "0009_stale_next_avengers",
|
||||
"when": 1782833951256,
|
||||
"tag": "0000_short_the_executioner",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user