0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 04:12:23 +01:00
posthog/plugin-server/tests/helpers/graphile-worker.ts
Yakko Majuri b89a2f8e28
refactor: rename Graphile to Graphile Worker (#12324)
* refactor: rename Graphile to Graphile Worker

* revert env var changes

* one more

* format readme

* add changed files
2022-10-19 11:38:25 -03:00

26 lines
791 B
TypeScript

import { makeWorkerUtils } from 'graphile-worker'
import { Pool } from 'pg'
import { PluginsServerConfig } from '../../src/types'
export async function resetGraphileWorkerSchema(serverConfig: PluginsServerConfig): Promise<void> {
const graphileUrl = serverConfig.JOB_QUEUE_GRAPHILE_URL || serverConfig.DATABASE_URL!
const db = new Pool({ connectionString: graphileUrl })
try {
await db.query('DROP SCHEMA graphile_worker CASCADE')
} catch (error) {
if (error.message !== 'schema "graphile_worker" does not exist') {
throw error
}
} finally {
await db.end()
}
const workerUtils = await makeWorkerUtils({
connectionString: graphileUrl,
})
await workerUtils.migrate()
await workerUtils.release()
}