KI-AGENT: Telefonie-Trunk in Firmeneinstellungen verschieben
This commit is contained in:
50
backend/db/migrations/0045_telephony_trunks.sql
Normal file
50
backend/db/migrations/0045_telephony_trunks.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
CREATE TABLE IF NOT EXISTS "telephony_trunks" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"tenant_id" bigint NOT NULL,
|
||||
"provider" text DEFAULT 'telekom' NOT NULL,
|
||||
"enabled" boolean DEFAULT false NOT NULL,
|
||||
"registrar" text DEFAULT 'tel.t-online.de' NOT NULL,
|
||||
"sip_user" text,
|
||||
"auth_user" text,
|
||||
"password" text,
|
||||
"caller_id" text,
|
||||
"inbound_extension" text DEFAULT '1001' NOT NULL,
|
||||
"outbound_prefix" text DEFAULT '0' NOT NULL,
|
||||
"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_trunks_tenant_id_tenants_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_trunks"
|
||||
ADD CONSTRAINT "telephony_trunks_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_trunks_created_by_auth_users_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_trunks"
|
||||
ADD CONSTRAINT "telephony_trunks_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_trunks_updated_by_auth_users_id_fk'
|
||||
) THEN
|
||||
ALTER TABLE "telephony_trunks"
|
||||
ADD CONSTRAINT "telephony_trunks_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 UNIQUE INDEX IF NOT EXISTS "telephony_trunks_tenant_provider_idx"
|
||||
ON "telephony_trunks" USING btree ("tenant_id", "provider");
|
||||
@@ -316,6 +316,13 @@
|
||||
"when": 1780160400000,
|
||||
"tag": "0044_telephony_calls",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 45,
|
||||
"version": "7",
|
||||
"when": 1780164000000,
|
||||
"tag": "0045_telephony_trunks",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ export * from "./tasks"
|
||||
export * from "./teams"
|
||||
export * from "./taxtypes"
|
||||
export * from "./telephony_calls"
|
||||
export * from "./telephony_trunks"
|
||||
export * from "./tenants"
|
||||
export * from "./texttemplates"
|
||||
export * from "./units"
|
||||
|
||||
48
backend/db/schema/telephony_trunks.ts
Normal file
48
backend/db/schema/telephony_trunks.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
pgTable,
|
||||
uuid,
|
||||
bigint,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core"
|
||||
|
||||
import { tenants } from "./tenants"
|
||||
import { authUsers } from "./auth_users"
|
||||
|
||||
export const telephonyTrunks = pgTable(
|
||||
"telephony_trunks",
|
||||
{
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
|
||||
tenantId: bigint("tenant_id", { mode: "number" })
|
||||
.notNull()
|
||||
.references(() => tenants.id, { onDelete: "cascade" }),
|
||||
|
||||
provider: text("provider").notNull().default("telekom"),
|
||||
enabled: boolean("enabled").notNull().default(false),
|
||||
registrar: text("registrar").notNull().default("tel.t-online.de"),
|
||||
|
||||
sipUser: text("sip_user"),
|
||||
authUser: text("auth_user"),
|
||||
password: text("password"),
|
||||
callerId: text("caller_id"),
|
||||
inboundExtension: text("inbound_extension").notNull().default("1001"),
|
||||
outboundPrefix: text("outbound_prefix").notNull().default("0"),
|
||||
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.notNull()
|
||||
.defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }),
|
||||
createdBy: uuid("created_by").references(() => authUsers.id),
|
||||
updatedBy: uuid("updated_by").references(() => authUsers.id),
|
||||
},
|
||||
(table) => ({
|
||||
tenantProviderIdx: uniqueIndex("telephony_trunks_tenant_provider_idx")
|
||||
.on(table.tenantId, table.provider),
|
||||
})
|
||||
)
|
||||
|
||||
export type TelephonyTrunk = typeof telephonyTrunks.$inferSelect
|
||||
export type NewTelephonyTrunk = typeof telephonyTrunks.$inferInsert
|
||||
Reference in New Issue
Block a user