feat: improve channel resilience and operations
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
ALTER TABLE "CmppConnectionState"
|
||||
ADD COLUMN "lastReconnectAttemptAt" TIMESTAMP(3),
|
||||
ADD COLUMN "nextReconnectAt" TIMESTAMP(3),
|
||||
ADD COLUMN "lastErrorCategory" TEXT;
|
||||
|
||||
CREATE INDEX "CmppConnectionState_status_nextReconnectAt_idx"
|
||||
ON "CmppConnectionState"("status", "nextReconnectAt");
|
||||
|
||||
-- Rollback:
|
||||
-- DROP INDEX "CmppConnectionState_status_nextReconnectAt_idx";
|
||||
-- ALTER TABLE "CmppConnectionState"
|
||||
-- DROP COLUMN "lastErrorCategory",
|
||||
-- DROP COLUMN "nextReconnectAt",
|
||||
-- DROP COLUMN "lastReconnectAttemptAt";
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE "SmsApplication"
|
||||
ALTER COLUMN "maxPhonesPerTask" SET DEFAULT 10000;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
ALTER TABLE "DailyReconciliationReport"
|
||||
ADD COLUMN "submittedUnits" INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN "unknownUnits" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "DailyProfitReport"
|
||||
ADD COLUMN "submittedUnits" INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN "unknownUnits" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE "DailyQualityReport"
|
||||
ADD COLUMN "submittedUnits" INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN "unknownUnits" INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE "DailyReconciliationReport"
|
||||
SET "submittedUnits" = "sentUnits",
|
||||
"unknownUnits" = GREATEST("sentUnits" - "successUnits" - "failedUnits", 0);
|
||||
|
||||
UPDATE "DailyProfitReport"
|
||||
SET "submittedUnits" = "sentUnits",
|
||||
"unknownUnits" = GREATEST("sentUnits" - "successUnits" - "failedUnits", 0);
|
||||
|
||||
UPDATE "DailyQualityReport"
|
||||
SET "submittedUnits" = "sentUnits",
|
||||
"unknownUnits" = GREATEST("sentUnits" - "successUnits" - "failedUnits", 0);
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
WITH ranked AS (
|
||||
SELECT
|
||||
id,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY "channelId", "connectionId"
|
||||
ORDER BY "updatedAt" DESC, "createdAt" DESC, id DESC
|
||||
) AS row_no
|
||||
FROM "CmppConnectionState"
|
||||
WHERE "applicationId" IS NULL
|
||||
)
|
||||
DELETE FROM "CmppConnectionState" state
|
||||
USING ranked
|
||||
WHERE state.id = ranked.id
|
||||
AND ranked.row_no > 1;
|
||||
|
||||
CREATE UNIQUE INDEX "CmppConnectionState_supplier_channel_connection_key"
|
||||
ON "CmppConnectionState"("channelId", "connectionId")
|
||||
WHERE "applicationId" IS NULL;
|
||||
|
||||
-- Rollback:
|
||||
-- DROP INDEX "CmppConnectionState_supplier_channel_connection_key";
|
||||
@@ -370,7 +370,7 @@ model SmsApplication {
|
||||
dailyLimit Int @default(100000)
|
||||
customerUnitPrice BigInt @default(0)
|
||||
queuePriority String @default("normal")
|
||||
maxPhonesPerTask Int @default(1000000)
|
||||
maxPhonesPerTask Int @default(10000)
|
||||
templateMismatchMode String @default("reject")
|
||||
downstreamReceiptRetryEnabled Boolean @default(true)
|
||||
downstreamUplinkRetryEnabled Boolean @default(true)
|
||||
@@ -785,6 +785,9 @@ model CmppConnectionState {
|
||||
lastDisconnectedAt DateTime?
|
||||
lastHeartbeatAt DateTime?
|
||||
reconnectCount Int @default(0)
|
||||
lastReconnectAttemptAt DateTime?
|
||||
nextReconnectAt DateTime?
|
||||
lastErrorCategory String?
|
||||
lastError String?
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
@@ -797,6 +800,7 @@ model CmppConnectionState {
|
||||
@@index([tenantId, status])
|
||||
@@index([applicationId, status])
|
||||
@@index([channelId, status])
|
||||
@@index([status, nextReconnectAt])
|
||||
}
|
||||
|
||||
model CmppDownstreamConnection {
|
||||
@@ -1436,7 +1440,9 @@ model DailyReconciliationReport {
|
||||
tenantName String
|
||||
applicationId String
|
||||
applicationName String
|
||||
submittedUnits Int @default(0)
|
||||
sentUnits Int @default(0)
|
||||
unknownUnits Int @default(0)
|
||||
successUnits Int @default(0)
|
||||
failedUnits Int @default(0)
|
||||
generatedAt DateTime @default(now())
|
||||
@@ -1458,7 +1464,9 @@ model DailyProfitReport {
|
||||
tenantName String?
|
||||
applicationId String?
|
||||
channelId String?
|
||||
submittedUnits Int @default(0)
|
||||
sentUnits Int @default(0)
|
||||
unknownUnits Int @default(0)
|
||||
successUnits Int @default(0)
|
||||
failedUnits Int @default(0)
|
||||
revenueCents BigInt @default(0)
|
||||
@@ -1488,7 +1496,9 @@ model DailyQualityReport {
|
||||
channelId String?
|
||||
signatureId String?
|
||||
drainageInfoId String?
|
||||
submittedUnits Int @default(0)
|
||||
sentUnits Int @default(0)
|
||||
unknownUnits Int @default(0)
|
||||
successUnits Int @default(0)
|
||||
failedUnits Int @default(0)
|
||||
successRateBps Int @default(0)
|
||||
|
||||
Reference in New Issue
Block a user