From 6c8e53947f165acec1791398d70fc53953df6cfe Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 08:41:08 -0300 Subject: [PATCH 1/6] Use pluginConfig ID instead of team + plugin id --- src/utils/db/sql.ts | 8 ++++---- src/worker/vm/lazy.ts | 2 +- tests/postgres/vm.lazy.test.ts | 2 +- tests/sql.test.ts | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) 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..dc50c320 100644 --- a/tests/postgres/vm.lazy.test.ts +++ b/tests/postgres/vm.lazy.test.ts @@ -97,7 +97,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 0f9a5a1e..86388258 100644 --- a/tests/sql.test.ts +++ b/tests/sql.test.ts @@ -149,10 +149,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], + [39], 'disablePlugin' ) }) @@ -162,7 +162,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([]) From b7b56ddc50c43f3c9e179214fa6a0cd70fd169fe Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 14:10:39 -0300 Subject: [PATCH 2/6] update test --- tests/postgres/vm.lazy.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/postgres/vm.lazy.test.ts b/tests/postgres/vm.lazy.test.ts index dc50c320..73124cc9 100644 --- a/tests/postgres/vm.lazy.test.ts +++ b/tests/postgres/vm.lazy.test.ts @@ -12,9 +12,10 @@ jest.mock('../../src/utils/db/error') jest.mock('../../src/utils/status') jest.mock('../../src/utils/db/sql') -const mockConfig = { +const x = { plugin_id: 60, team_id: 2, + id: 39, } describe('LazyPluginVM', () => { From 5ca202b58642bb6a2b554aa6c45575cdef82357a Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 14:23:15 -0300 Subject: [PATCH 3/6] update --- tests/sql.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sql.test.ts b/tests/sql.test.ts index d8a1d5df..a95e23e4 100644 --- a/tests/sql.test.ts +++ b/tests/sql.test.ts @@ -152,7 +152,7 @@ describe('disablePlugin', () => { 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'`, + `UPDATE posthog_pluginconfig SET enabled='f' WHERE id=$1 AND enabled='t'`, [39], 'disablePlugin' ) From c70887b1447a30e40ec828a59ef1f0d4b9086cba Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 14:55:15 -0300 Subject: [PATCH 4/6] fix typo --- tests/postgres/vm.lazy.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/postgres/vm.lazy.test.ts b/tests/postgres/vm.lazy.test.ts index 73124cc9..64ec002e 100644 --- a/tests/postgres/vm.lazy.test.ts +++ b/tests/postgres/vm.lazy.test.ts @@ -12,10 +12,9 @@ jest.mock('../../src/utils/db/error') jest.mock('../../src/utils/status') jest.mock('../../src/utils/db/sql') -const x = { +const mockConfig = { plugin_id: 60, team_id: 2, - id: 39, } describe('LazyPluginVM', () => { @@ -98,7 +97,7 @@ describe('LazyPluginVM', () => { expect(status.warn).toHaveBeenCalledWith('⚠️', 'Failed to load some plugin') expect(processError).toHaveBeenCalledWith(mockServer, mockConfig, error) - expect(disablePlugin).toHaveBeenCalledWith(mockServer, 39) + expect(disablePlugin).toHaveBeenCalledWith(mockServer, 2, 60) expect(mockServer.db.createPluginLogEntry).toHaveBeenCalledWith( mockConfig, PluginLogEntrySource.System, From 8363714db15ab323ec3ef79941e6c009bdc4861b Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 15:17:35 -0300 Subject: [PATCH 5/6] final fix --- tests/postgres/vm.lazy.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/postgres/vm.lazy.test.ts b/tests/postgres/vm.lazy.test.ts index 64ec002e..dc50c320 100644 --- a/tests/postgres/vm.lazy.test.ts +++ b/tests/postgres/vm.lazy.test.ts @@ -97,7 +97,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, From af16971546e0c5a2e666bfed076995b29c5e0d0b Mon Sep 17 00:00:00 2001 From: yakkomajuri Date: Tue, 18 May 2021 16:01:53 -0300 Subject: [PATCH 6/6] udate vm tests --- tests/postgres/vm.lazy.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/postgres/vm.lazy.test.ts b/tests/postgres/vm.lazy.test.ts index dc50c320..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', () => {