diff --git a/src/utils/db/sql.ts b/src/utils/db/sql.ts index fcf395d6..ddcd7645 100644 --- a/src/utils/db/sql.ts +++ b/src/utils/db/sql.ts @@ -2,8 +2,8 @@ import { Plugin, PluginAttachmentDB, PluginConfig, + PluginConfigId, PluginError, - PluginId, PluginLogEntrySource, PluginLogEntryType, PluginsServer, @@ -73,10 +73,10 @@ export async function setError( } } -export async function disablePlugin(server: PluginsServer, teamId: TeamId, pluginId: PluginId): Promise { +export async function disablePlugin(server: PluginsServer, pluginConfigId: PluginConfigId): Promise { await server.db.postgresQuery( - `UPDATE posthog_pluginconfig SET enabled='f' WHERE team_id=$1 AND plugin_id=$2 AND enabled='t'`, - [teamId, pluginId], + `UPDATE posthog_pluginconfig SET enabled='f' WHERE id=$1 AND enabled='t'`, + [pluginConfigId], 'disablePlugin' ) } diff --git a/src/worker/vm/lazy.ts b/src/worker/vm/lazy.ts index a17c9410..6e654d19 100644 --- a/src/worker/vm/lazy.ts +++ b/src/worker/vm/lazy.ts @@ -46,7 +46,7 @@ export class LazyPluginVM { server.instanceId ) status.warn('⚠️', `Failed to load ${logInfo}`) - void disablePlugin(server, pluginConfig.team_id, pluginConfig.plugin_id) + void disablePlugin(server, pluginConfig.id) void processError(server, pluginConfig, error) resolve(null) } diff --git a/tests/postgres/vm.lazy.test.ts b/tests/postgres/vm.lazy.test.ts index 64ec002e..7ad072aa 100644 --- a/tests/postgres/vm.lazy.test.ts +++ b/tests/postgres/vm.lazy.test.ts @@ -15,6 +15,7 @@ jest.mock('../../src/utils/db/sql') const mockConfig = { plugin_id: 60, team_id: 2, + id: 39, } describe('LazyPluginVM', () => { @@ -97,7 +98,7 @@ describe('LazyPluginVM', () => { expect(status.warn).toHaveBeenCalledWith('⚠️', 'Failed to load some plugin') expect(processError).toHaveBeenCalledWith(mockServer, mockConfig, error) - expect(disablePlugin).toHaveBeenCalledWith(mockServer, 2, 60) + expect(disablePlugin).toHaveBeenCalledWith(mockServer, 39) expect(mockServer.db.createPluginLogEntry).toHaveBeenCalledWith( mockConfig, PluginLogEntrySource.System, diff --git a/tests/sql.test.ts b/tests/sql.test.ts index 47e9b8ef..a95e23e4 100644 --- a/tests/sql.test.ts +++ b/tests/sql.test.ts @@ -150,10 +150,10 @@ describe('disablePlugin', () => { test('disablePlugin query builds correctly', async () => { server.db.postgresQuery = jest.fn() as any - await disablePlugin(server, 2, 60) + await disablePlugin(server, 39) expect(server.db.postgresQuery).toHaveBeenCalledWith( - `UPDATE posthog_pluginconfig SET enabled='f' WHERE team_id=$1 AND plugin_id=$2 AND enabled='t'`, - [2, 60], + `UPDATE posthog_pluginconfig SET enabled='f' WHERE id=$1 AND enabled='t'`, + [39], 'disablePlugin' ) }) @@ -163,7 +163,7 @@ describe('disablePlugin', () => { expect(rowsBefore[0].plugin_id).toEqual(60) expect(rowsBefore[0].enabled).toEqual(true) - await disablePlugin(server, 2, 60) + await disablePlugin(server, 39) const rowsAfter = await getPluginConfigRows(server) expect(rowsAfter).toEqual([])