Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/utils/db/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
Plugin,
PluginAttachmentDB,
PluginConfig,
PluginConfigId,
PluginError,
PluginId,
PluginLogEntrySource,
PluginLogEntryType,
PluginsServer,
Expand Down Expand Up @@ -73,10 +73,10 @@ export async function setError(
}
}

export async function disablePlugin(server: PluginsServer, teamId: TeamId, pluginId: PluginId): Promise<void> {
export async function disablePlugin(server: PluginsServer, pluginConfigId: PluginConfigId): Promise<void> {
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'
)
}
2 changes: 1 addition & 1 deletion src/worker/vm/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/postgres/vm.lazy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jest.mock('../../src/utils/db/sql')
const mockConfig = {
plugin_id: 60,
team_id: 2,
id: 39,
}

describe('LazyPluginVM', () => {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
Expand All @@ -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([])
Expand Down