diff --git a/packages/database/lib/migrations/20240621155627_active_logs_activitylogid.cjs b/packages/database/lib/migrations/20240621155627_active_logs_activitylogid.cjs new file mode 100644 index 0000000000..b2147e579c --- /dev/null +++ b/packages/database/lib/migrations/20240621155627_active_logs_activitylogid.cjs @@ -0,0 +1,18 @@ +/** + * @param {import('knex').Knex} knex + */ +exports.up = function (knex) { + return knex.schema.alterTable('_nango_active_logs', function (trx) { + trx.dropColumn('activity_log_id'); + }); +}; + +/** + * @param {import('knex').Knex} knex + */ +exports.down = function (knex) { + return knex.schema.alterTable('_nango_active_logs', function (trx) { + trx.integer('activity_log_id').unsigned(); + trx.foreign('activity_log_id').references('id').inTable('_nango_activity_logs').onDelete('CASCADE'); + }); +}; diff --git a/packages/server/lib/hooks/hooks.ts b/packages/server/lib/hooks/hooks.ts index 897e0e1c86..374022577c 100644 --- a/packages/server/lib/hooks/hooks.ts +++ b/packages/server/lib/hooks/hooks.ts @@ -164,7 +164,6 @@ export const connectionRefreshFailed = async ({ type: 'auth', action: 'token_refresh', connection_id: connection.id!, - activity_log_id: -1, log_id: logCtx.id, active: true }); diff --git a/packages/shared/lib/services/connection.service.ts b/packages/shared/lib/services/connection.service.ts index 13b3f7712c..c7abd0a621 100644 --- a/packages/shared/lib/services/connection.service.ts +++ b/packages/shared/lib/services/connection.service.ts @@ -533,7 +533,6 @@ class ConnectionService { '_nango_connections.metadata', db.knex.raw(` (SELECT json_build_object( - 'activity_log_id', activity_log_id, 'log_id', log_id ) FROM ${ACTIVE_LOG_TABLE} diff --git a/packages/shared/lib/services/notification/error.service.ts b/packages/shared/lib/services/notification/error.service.ts index 4295d2395f..0a64a79382 100644 --- a/packages/shared/lib/services/notification/error.service.ts +++ b/packages/shared/lib/services/notification/error.service.ts @@ -7,12 +7,12 @@ import db from '@nangohq/database'; const DB_TABLE = '_nango_active_logs'; -type ErrorNotification = Required>; +type ErrorNotification = Required>; type SyncErrorNotification = ErrorNotification & Required>; export const errorNotificationService = { auth: { - create: async ({ type, action, connection_id, activity_log_id, log_id, active }: ErrorNotification): Promise> => { + create: async ({ type, action, connection_id, log_id, active }: ErrorNotification): Promise> => { return await db.knex.transaction(async (trx) => { await errorNotificationService.auth.clear({ connection_id, trx }); const created = await trx @@ -21,7 +21,6 @@ export const errorNotificationService = { type, action, connection_id, - activity_log_id, log_id, active }) @@ -42,7 +41,7 @@ export const errorNotificationService = { } }, sync: { - create: async ({ type, action, sync_id, connection_id, activity_log_id, log_id, active }: SyncErrorNotification): Promise> => { + create: async ({ type, action, sync_id, connection_id, log_id, active }: SyncErrorNotification): Promise> => { return await db.knex.transaction(async (trx) => { await errorNotificationService.sync.clear({ sync_id, connection_id, trx }); const created = await trx @@ -52,7 +51,6 @@ export const errorNotificationService = { action, sync_id, connection_id, - activity_log_id, log_id, active }) diff --git a/packages/shared/lib/services/sync/run.service.ts b/packages/shared/lib/services/sync/run.service.ts index f862af72b1..c183bb3407 100644 --- a/packages/shared/lib/services/sync/run.service.ts +++ b/packages/shared/lib/services/sync/run.service.ts @@ -976,7 +976,6 @@ export default class SyncRun { type: 'sync', sync_id: this.syncId, connection_id: this.nangoConnection.id, - activity_log_id: this.activityLogId as unknown as number, log_id: this.logCtx?.id, active: true }); diff --git a/packages/shared/lib/services/sync/sync.service.ts b/packages/shared/lib/services/sync/sync.service.ts index 61873a1666..401e6b407c 100644 --- a/packages/shared/lib/services/sync/sync.service.ts +++ b/packages/shared/lib/services/sync/sync.service.ts @@ -222,16 +222,11 @@ export const getSyncs = async ( `${SYNC_SCHEDULE_TABLE}.offset`, `${SYNC_SCHEDULE_TABLE}.status as schedule_status`, `${SYNC_CONFIG_TABLE}.models`, - `${ACTIVE_LOG_TABLE}.activity_log_id as error_activity_log_id`, `${ACTIVE_LOG_TABLE}.log_id as error_log_id`, db.knex.raw(` - CASE - WHEN COUNT(${ACTIVE_LOG_TABLE}.activity_log_id) = 0 THEN NULL - ELSE json_build_object( - 'activity_log_id', ${ACTIVE_LOG_TABLE}.activity_log_id, - 'log_id', ${ACTIVE_LOG_TABLE}.log_id - ) - END as active_logs + json_build_object( + 'log_id', ${ACTIVE_LOG_TABLE}.log_id + ) as active_logs `), db.knex.raw( `( @@ -281,7 +276,6 @@ export const getSyncs = async ( .groupBy( `${TABLE}.id`, `${SYNC_SCHEDULE_TABLE}.frequency`, - `${ACTIVE_LOG_TABLE}.activity_log_id`, `${ACTIVE_LOG_TABLE}.log_id`, `${SYNC_SCHEDULE_TABLE}.offset`, `${SYNC_SCHEDULE_TABLE}.status`, diff --git a/packages/types/lib/notification/active-logs/db.ts b/packages/types/lib/notification/active-logs/db.ts index fdce3bac51..cdf6e744c9 100644 --- a/packages/types/lib/notification/active-logs/db.ts +++ b/packages/types/lib/notification/active-logs/db.ts @@ -5,10 +5,9 @@ export interface ActiveLog extends Timestamps { type: string; action: string; connection_id: number; - activity_log_id: number; log_id: string; active: boolean; sync_id: string | null; } -export type ActiveLogIds = Pick; +export type ActiveLogIds = Pick; diff --git a/packages/webapp/src/pages/Connection/Show.tsx b/packages/webapp/src/pages/Connection/Show.tsx index c96a7f1433..d487e13db7 100644 --- a/packages/webapp/src/pages/Connection/Show.tsx +++ b/packages/webapp/src/pages/Connection/Show.tsx @@ -234,7 +234,7 @@ We could not retrieve and/or refresh your access token due to the following erro onClick={() => setActiveTab(Tabs.Syncs)} > Syncs - {syncs && syncs.find((sync) => typeof sync.active_logs?.activity_log_id === 'number') && ( + {syncs && syncs.some((sync) => sync.active_logs?.log_id) && ( )} @@ -268,7 +268,7 @@ We could not retrieve and/or refresh your access token due to the following erro )} - {activeTab === Tabs.Syncs && syncs && syncs.find((sync) => typeof sync.active_logs?.activity_log_id === 'number') && ( + {activeTab === Tabs.Syncs && syncs && syncs.some((sync) => sync.active_logs?.log_id) && (
Last sync execution failed for the following sync - {syncs.filter((sync) => typeof sync.active_logs?.activity_log_id === 'number').length > 1 ? 's' : ''}:{' '} + {syncs.filter((sync) => sync.active_logs?.log_id).length > 1 ? 's' : ''}:{' '} {syncs - .filter((sync) => typeof sync.active_logs?.activity_log_id === 'number') + .filter((sync) => sync.active_logs?.log_id) .map((sync, index) => ( {sync.name} ( - + logs - ){index < syncs.filter((sync) => typeof sync.active_logs?.activity_log_id === 'number').length - 1 && ', '} + ){index < syncs.filter((sync) => sync.active_logs?.log_id).length - 1 && ', '} ))} . diff --git a/packages/webapp/src/pages/Connection/Syncs.tsx b/packages/webapp/src/pages/Connection/Syncs.tsx index af97a8411c..30b63a0d20 100644 --- a/packages/webapp/src/pages/Connection/Syncs.tsx +++ b/packages/webapp/src/pages/Connection/Syncs.tsx @@ -419,7 +419,7 @@ export default function Syncs({ syncs, connection, provider, reload, loaded, syn