@recombine-ai/platform 0.2.6-test.5 → 0.2.6-test.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-analytics.d.ts","sourceRoot":"","sources":["../src/postgres-analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAE9D,OAAO,EACH,SAAS,EAGT,qBAAqB,EAGxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAA;AAI1E,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;IACf,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,CAAA;CAC3B;AAID,MAAM,WAAW,eAAe;IAC5B,
|
|
1
|
+
{"version":3,"file":"postgres-analytics.d.ts","sourceRoot":"","sources":["../src/postgres-analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAE9D,OAAO,EACH,SAAS,EAGT,qBAAqB,EAGxB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAA;AAI1E,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;IACf,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,eAAe,CAAC,E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|
await this.upsertConversation(client, conversation);
|
|
90
90
|
if (phoneCall) {
|
|
91
|
-
await this.upsertPhoneCall(client, phoneCall);
|
|
91
|
+
await this.upsertPhoneCall(client, conversation.conversationId, phoneCall);
|
|
92
92
|
}
|
|
93
93
|
await client.query('COMMIT');
|
|
94
94
|
}
|
|
@@ -111,12 +111,13 @@ class PostgresConversationRepository {
|
|
|
111
111
|
duration_seconds
|
|
112
112
|
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
113
113
|
ON CONFLICT (conversation_id) DO UPDATE SET
|
|
114
|
-
agent_id = EXCLUDED.agent_id,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
agent_id = COALESCE(conversations.agent_id, EXCLUDED.agent_id),
|
|
115
|
+
region = COALESCE(conversations.region, EXCLUDED.region),
|
|
116
|
+
ended_at = COALESCE(conversations.ended_at, EXCLUDED.ended_at),
|
|
117
|
+
duration_seconds = COALESCE(
|
|
118
|
+
conversations.duration_seconds,
|
|
119
|
+
EXCLUDED.duration_seconds
|
|
120
|
+
),
|
|
120
121
|
updated_at = now()`, [
|
|
121
122
|
conversation.conversationId,
|
|
122
123
|
conversation.agentId ?? null,
|
|
@@ -127,7 +128,7 @@ class PostgresConversationRepository {
|
|
|
127
128
|
conversation.durationSeconds ?? null,
|
|
128
129
|
]);
|
|
129
130
|
}
|
|
130
|
-
async upsertPhoneCall(client, phoneCall) {
|
|
131
|
+
async upsertPhoneCall(client, conversationId, phoneCall) {
|
|
131
132
|
await client.query(`INSERT INTO phone_calls (
|
|
132
133
|
conversation_id,
|
|
133
134
|
phone_number,
|
|
@@ -135,10 +136,10 @@ class PostgresConversationRepository {
|
|
|
135
136
|
ended_reason
|
|
136
137
|
) VALUES ($1, $2, $3, $4)
|
|
137
138
|
ON CONFLICT (conversation_id) DO UPDATE SET
|
|
138
|
-
phone_number = EXCLUDED.phone_number,
|
|
139
|
-
recording_url = EXCLUDED.recording_url,
|
|
140
|
-
ended_reason = EXCLUDED.ended_reason`, [
|
|
141
|
-
|
|
139
|
+
phone_number = COALESCE(phone_calls.phone_number, EXCLUDED.phone_number),
|
|
140
|
+
recording_url = COALESCE(phone_calls.recording_url, EXCLUDED.recording_url),
|
|
141
|
+
ended_reason = COALESCE(phone_calls.ended_reason, EXCLUDED.ended_reason)`, [
|
|
142
|
+
conversationId,
|
|
142
143
|
phoneCall.phoneNumber ?? null,
|
|
143
144
|
phoneCall.recordingUrl ?? null,
|
|
144
145
|
phoneCall.endedReason ?? null,
|
|
@@ -201,8 +202,11 @@ const migrations = [
|
|
|
201
202
|
];
|
|
202
203
|
async function migrateAnalyticsDatabase(pool) {
|
|
203
204
|
const client = await pool.connect();
|
|
205
|
+
let lockAcquired = false;
|
|
206
|
+
let migrationFailed = false;
|
|
204
207
|
try {
|
|
205
208
|
await client.query("SELECT pg_advisory_lock(hashtext('recombine_analytics_migrations'))");
|
|
209
|
+
lockAcquired = true;
|
|
206
210
|
await client.query(`
|
|
207
211
|
CREATE TABLE IF NOT EXISTS analytics_schema_migrations (
|
|
208
212
|
version integer PRIMARY KEY,
|
|
@@ -228,9 +232,29 @@ async function migrateAnalyticsDatabase(pool) {
|
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
234
|
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
migrationFailed = true;
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
await releaseAnalyticsMigrationClient(client, lockAcquired, migrationFailed);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function releaseAnalyticsMigrationClient(client, lockAcquired, migrationFailed) {
|
|
244
|
+
let discardClient = false;
|
|
245
|
+
try {
|
|
246
|
+
if (lockAcquired) {
|
|
247
|
+
await client.query("SELECT pg_advisory_unlock(hashtext('recombine_analytics_migrations'))");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
discardClient = true;
|
|
252
|
+
if (!migrationFailed) {
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
231
256
|
finally {
|
|
232
|
-
|
|
233
|
-
client.release();
|
|
257
|
+
client.release(discardClient);
|
|
234
258
|
}
|
|
235
259
|
}
|
|
236
260
|
async function createPostgresAnalyticsServices(config) {
|