-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathcustomRunner.ts
More file actions
50 lines (47 loc) · 1.47 KB
/
customRunner.ts
File metadata and controls
50 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { resolve } from 'path'
import { Client } from 'pg'
import runner, { RunnerOption } from '../../dist'
import { RunnerOptionDir, RunnerOptionMigrations } from '../../dist/types'
type TestOptions = {
count?: number
expectedUpLength?: number
expectedDownLength?: number
}
type Options = ({ databaseUrl: string } & TestOptions) | ({ dbClient: Client } & TestOptions)
/* eslint-disable no-console */
// eslint-disable-next-line import/prefer-default-export
export const run = async (options: Options): Promise<boolean> => {
const opts: Omit<RunnerOption, 'direction'> & Options & (RunnerOptionDir | RunnerOptionMigrations) = {
migrationsTable: 'migrations',
dir: resolve(__dirname, 'migrations'),
expectedUpLength: 2,
expectedDownLength: 2,
...options,
}
try {
const upResult = await runner({
...opts,
direction: 'up',
})
if (upResult.length !== opts.expectedUpLength) {
console.error(`There should be exactly ${opts.expectedUpLength} migrations processed`)
return false
}
console.log('Up success')
console.log(upResult)
const downResult = await runner({
...opts,
direction: 'down',
})
if (downResult.length !== opts.expectedDownLength) {
console.error(`There should be exactly ${opts.expectedDownLength} migrations processed`)
return false
}
console.log('Down success')
console.log(downResult)
return true
} catch (err) {
console.error(err)
return false
}
}