Skip to content
This repository was archived by the owner on Apr 19, 2020. It is now read-only.

Commit fc61f73

Browse files
committed
Update dependency: @synor/core
1 parent 1215d32 commit fc61f73

File tree

5 files changed

+351
-41
lines changed

5 files changed

+351
-41
lines changed

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"test": "jest"
2828
},
2929
"dependencies": {
30-
"better-sqlite3": "^5.4.3",
30+
"better-sqlite3": "^6.0.1",
3131
"connection-string": "^3.1.1",
3232
"debug": "^4.1.1"
3333
},
3434
"devDependencies": {
35-
"@synor/core": "^0.8.2",
35+
"@synor/core": "^0.9.0",
3636
"@types/better-sqlite3": "^5.4.0",
3737
"@types/debug": "^4.1.5",
3838
"@types/jest": "^24.0.25",
@@ -42,7 +42,7 @@
4242
"eslint": "^6.8.0",
4343
"eslint-config-prettier": "^6.9.0",
4444
"eslint-config-standard-with-typescript": "^11.0.1",
45-
"eslint-plugin-import": "^2.20.0",
45+
"eslint-plugin-import": "^2.20.1",
4646
"eslint-plugin-node": "^11.0.0",
4747
"eslint-plugin-prettier": "^3.1.2",
4848
"eslint-plugin-promise": "^4.2.1",
@@ -59,7 +59,7 @@
5959
"typescript": "^3.7.4"
6060
},
6161
"peerDependencies": {
62-
"@synor/core": "^0.8.2"
62+
"@synor/core": "^0.9.0"
6363
},
6464
"publishConfig": {
6565
"access": "public"

Diff for: src/__snapshots__/index.test.ts.snap

+28-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Array [
6565
]
6666
`;
6767

68-
exports[`methods run 2`] = `
68+
exports[`methods run (with body) 2`] = `
6969
Array [
7070
Object {
7171
"applied_at": "2020-01-01T00:00:00.000Z",
@@ -102,3 +102,30 @@ Array [
102102
},
103103
]
104104
`;
105+
106+
exports[`methods run (with run) 1`] = `
107+
Array [
108+
Object {
109+
"applied_at": "2020-01-01T00:00:00.000Z",
110+
"applied_by": "Synor",
111+
"dirty": 0,
112+
"execution_time": 0,
113+
"hash": "",
114+
"id": 1,
115+
"title": "Base Migration",
116+
"type": "do",
117+
"version": "0",
118+
},
119+
Object {
120+
"applied_at": "2020-01-01T00:00:00.000Z",
121+
"applied_by": "Jest",
122+
"dirty": 0,
123+
"execution_time": 0,
124+
"hash": "hash-02-do",
125+
"id": 2,
126+
"title": "Test Two",
127+
"type": "do",
128+
"version": "02",
129+
},
130+
]
131+
`;

Diff for: src/index.test.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ const getTableColumnCount = (
2727
.all({ tableName }).length
2828
}
2929

30-
const migrationSource: Record<'01.do' | '01.undo', MigrationSource> = {
30+
const migrationSource: Record<
31+
'01.do' | '01.undo' | '02.do',
32+
MigrationSource
33+
> = {
3134
'01.do': {
3235
version: '01',
3336
type: 'do',
@@ -41,6 +44,15 @@ const migrationSource: Record<'01.do' | '01.undo', MigrationSource> = {
4144
title: 'Test One',
4245
body: 'SELEC -1;',
4346
hash: 'hash-01-undo'
47+
},
48+
'02.do': {
49+
version: '02',
50+
type: 'do',
51+
title: 'Test Two',
52+
hash: 'hash-02-do',
53+
run: async (client: Database) => {
54+
client.exec('SELECT 2;')
55+
}
4456
}
4557
}
4658

@@ -246,7 +258,7 @@ describe('methods', () => {
246258
expect(getTableColumnCount(database, schemaName, tableName)).toBe(0)
247259
})
248260

249-
test('run', async () => {
261+
test('run (with body)', async () => {
250262
await expect(engine.run(migrationSource['01.do'])).resolves.toBeUndefined()
251263
await expect(
252264
engine.run(migrationSource['01.undo'])
@@ -263,6 +275,18 @@ describe('methods', () => {
263275
await engine.drop()
264276
})
265277

278+
test('run (with run)', async () => {
279+
await expect(engine.run(migrationSource['02.do'])).resolves.toBeUndefined()
280+
281+
const rows = database
282+
.prepare(`SELECT * FROM ${schemaName}.${tableName};`)
283+
.all()
284+
285+
expect(rows).toMatchSnapshot()
286+
287+
await engine.drop()
288+
})
289+
266290
test('repair', async () => {
267291
await expect(engine.run(migrationSource['01.do'])).resolves.toBeUndefined()
268292
await expect(

Diff for: src/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ type DatabaseEngine = import('@synor/core').DatabaseEngine
1010
type DatabaseEngineFactory = import('@synor/core').DatabaseEngineFactory
1111
type MigrationSource = import('@synor/core').MigrationSource
1212

13+
export type MigrationSourceContentRunner = (client: Database) => Promise<void>
14+
1315
export const SQLiteDatabaseEngine: DatabaseEngineFactory = (
1416
uri,
1517
{ baseVersion, getUserInfo }
@@ -61,14 +63,19 @@ export const SQLiteDatabaseEngine: DatabaseEngineFactory = (
6163
type,
6264
title,
6365
hash,
64-
body
66+
body,
67+
run
6568
}: MigrationSource) => {
6669
let dirty = false
6770

6871
const startTime = performance.now()
6972

7073
try {
71-
database.exec(body)
74+
if (body) {
75+
database.exec(body)
76+
} else {
77+
await (run as MigrationSourceContentRunner)(database)
78+
}
7279
} catch (err) {
7380
dirty = true
7481

0 commit comments

Comments
 (0)