KI-AGENT: Anrufhistorie für Telefonie ergänzen
This commit is contained in:
57
backend/db/migrations/0044_telephony_calls.sql
Normal file
57
backend/db/migrations/0044_telephony_calls.sql
Normal file
@@ -0,0 +1,57 @@
|
||||
CREATE TABLE IF NOT EXISTS "telephony_calls" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"tenant_id" bigint NOT NULL,
|
||||
"direction" text NOT NULL,
|
||||
"status" text DEFAULT 'ringing' NOT NULL,
|
||||
"local_extension" text,
|
||||
"remote_number" text,
|
||||
"remote_display_name" text,
|
||||
"sip_call_id" text,
|
||||
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"answered_at" timestamp with time zone,
|
||||
"ended_at" timestamp with time zone,
|
||||
"duration_seconds" integer,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone,
|
||||
"created_by" uuid,
|
||||
"updated_by" uuid
|
||||
);
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'telephony_calls_tenant_id_tenants_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_calls"
|
||||
ADD CONSTRAINT "telephony_calls_tenant_id_tenants_id_fk"
|
||||
FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id")
|
||||
ON DELETE cascade ON UPDATE no action;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'telephony_calls_created_by_auth_users_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_calls"
|
||||
ADD CONSTRAINT "telephony_calls_created_by_auth_users_id_fk"
|
||||
FOREIGN KEY ("created_by") REFERENCES "public"."auth_users"("id")
|
||||
ON DELETE no action ON UPDATE no action;
|
||||
END IF;
|
||||
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'telephony_calls_updated_by_auth_users_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_calls"
|
||||
ADD CONSTRAINT "telephony_calls_updated_by_auth_users_id_fk"
|
||||
FOREIGN KEY ("updated_by") REFERENCES "public"."auth_users"("id")
|
||||
ON DELETE no action ON UPDATE no action;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "telephony_calls_tenant_started_idx"
|
||||
ON "telephony_calls" USING btree ("tenant_id", "started_at");
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "telephony_calls_created_by_idx"
|
||||
ON "telephony_calls" USING btree ("tenant_id", "created_by");
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "telephony_calls_sip_call_idx"
|
||||
ON "telephony_calls" USING btree ("tenant_id", "sip_call_id");
|
||||
@@ -309,6 +309,13 @@
|
||||
"when": 1780156800000,
|
||||
"tag": "0043_communication_rooms",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 44,
|
||||
"version": "7",
|
||||
"when": 1780160400000,
|
||||
"tag": "0044_telephony_calls",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user