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

Commit 0d4b700

Browse files
committed
Update dependency: @synor/core
1 parent afc0926 commit 0d4b700

File tree

5 files changed

+102
-32
lines changed

5 files changed

+102
-32
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
"test": "jest"
2929
},
3030
"dependencies": {
31-
"connection-string": "^3.1.0",
31+
"connection-string": "^3.1.1",
3232
"debug": "^4.1.1",
33-
"pg": "^7.15.1"
33+
"pg": "^7.18.2"
3434
},
3535
"devDependencies": {
36-
"@synor/core": "^0.6.1",
36+
"@synor/core": "^0.9.0",
3737
"@types/debug": "^4.1.5",
3838
"@types/jest": "^24.0.25",
3939
"@types/pg": "^7.14.1",
@@ -43,7 +43,7 @@
4343
"eslint": "^6.8.0",
4444
"eslint-config-prettier": "^6.9.0",
4545
"eslint-config-standard-with-typescript": "^11.0.1",
46-
"eslint-plugin-import": "^2.20.0",
46+
"eslint-plugin-import": "^2.20.1",
4747
"eslint-plugin-node": "^11.0.0",
4848
"eslint-plugin-prettier": "^3.1.2",
4949
"eslint-plugin-promise": "^4.2.1",
@@ -53,14 +53,14 @@
5353
"lint-staged": "^9.4.2",
5454
"prettier": "^1.18.2",
5555
"pretty-quick": "^2.0.0",
56-
"rimraf": "^3.0.0",
56+
"rimraf": "^3.0.2",
5757
"rollup-plugin-typescript2": "^0.25.2",
5858
"ts-jest": "^24.3.0",
5959
"ts-node": "^8.5.4",
6060
"typescript": "^3.7.4"
6161
},
6262
"peerDependencies": {
63-
"@synor/core": "^0.6.1"
63+
"@synor/core": "^0.9.0"
6464
},
6565
"publishConfig": {
6666
"access": "public"

src/__snapshots__/index.test.ts.snap

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Array [
6565
]
6666
`;
6767

68-
exports[`methods run 1`] = `
68+
exports[`methods run (with body) 1`] = `
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": false,
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": false,
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+
`;

src/index.test.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ const getTableColumnCount = async (
2525
.then(result => result.rows.length)
2626
}
2727

28-
const migrationSource: Record<'01.do' | '01.undo', MigrationSource> = {
28+
const migrationSource: Record<
29+
'01.do' | '01.undo' | '02.do',
30+
MigrationSource
31+
> = {
2932
'01.do': {
3033
version: '01',
3134
type: 'do',
@@ -39,6 +42,15 @@ const migrationSource: Record<'01.do' | '01.undo', MigrationSource> = {
3942
title: 'Test One',
4043
body: 'SELEC -1;',
4144
hash: 'hash-01-undo'
45+
},
46+
'02.do': {
47+
version: '02',
48+
type: 'do',
49+
title: 'Test Two',
50+
hash: 'hash-02-do',
51+
run: (client: Client) => {
52+
return client.query(`SELECT 2;`)
53+
}
4254
}
4355
}
4456

@@ -334,7 +346,7 @@ describe('methods', () => {
334346
).resolves.toBe(0)
335347
})
336348

337-
test('run', async () => {
349+
test('run (with body)', async () => {
338350
await expect(engine.run(migrationSource['01.do'])).resolves.toBeUndefined()
339351
await expect(engine.run(migrationSource['01.undo'])).rejects.toThrow()
340352

@@ -346,6 +358,17 @@ describe('methods', () => {
346358
await engine.drop()
347359
})
348360

361+
test('run (with run)', async () => {
362+
await expect(engine.run(migrationSource['02.do'])).resolves.toBeUndefined()
363+
364+
const { rows } = await client.query(
365+
`SELECT * FROM ${schemaName}.${tableName};`
366+
)
367+
expect(rows).toMatchSnapshot()
368+
369+
await engine.drop()
370+
})
371+
349372
test('repair', async () => {
350373
await expect(engine.run(migrationSource['01.do'])).resolves.toBeUndefined()
351374
await expect(engine.run(migrationSource['01.undo'])).rejects.toThrow()

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type DatabaseEngine = import('@synor/core').DatabaseEngine
99
type DatabaseEngineFactory = import('@synor/core').DatabaseEngineFactory
1010
type MigrationSource = import('@synor/core').MigrationSource
1111

12+
export type MigrationSourceContentRunner = (client: Client) => Promise<void>
13+
1214
export const PostgreSQLDatabaseEngine: DatabaseEngineFactory = (
1315
uri,
1416
{ baseVersion, getAdvisoryLockId, getUserInfo }
@@ -77,14 +79,19 @@ export const PostgreSQLDatabaseEngine: DatabaseEngineFactory = (
7779
type,
7880
title,
7981
hash,
80-
body
82+
body,
83+
run
8184
}: MigrationSource) => {
8285
let dirty = false
8386

8487
const startTime = performance.now()
8588

8689
try {
87-
await client.query(body)
90+
if (body) {
91+
await client.query(body)
92+
} else {
93+
await (run as MigrationSourceContentRunner)(client)
94+
}
8895
} catch (err) {
8996
dirty = true
9097

yarn.lock

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,10 @@
894894
dependencies:
895895
any-observable "^0.3.0"
896896

897-
"@synor/core@^0.6.1":
898-
version "0.6.1"
899-
resolved "https://registry.yarnpkg.com/@synor/core/-/core-0.6.1.tgz#16db5a677c6a046b467c455e45aa7ddb16828588"
900-
integrity sha512-bJIFL6jLemkz9RoW0kcQXOypiDq4u9uHA3WXl5tV2D2lUTGkzPTNsZ63dparuInVpqwghERHNvkPHFxTeo9BFw==
897+
"@synor/core@^0.9.0":
898+
version "0.9.0"
899+
resolved "https://registry.yarnpkg.com/@synor/core/-/core-0.9.0.tgz#f05bf65ec4f86eb85c01e774ae0f13e6116e59fe"
900+
integrity sha512-ZKR1Zulm2DUWu5CdJs+T08lRIBsLdg8K+K5rR+LBOZwml+u4a5WqAIVPA4BbulyFrNIWjjwaDO7gHq9KB/iKxQ==
901901
dependencies:
902902
debug "^4.1.1"
903903
lodash.defaultsdeep "^4.6.1"
@@ -1840,10 +1840,10 @@ concat-with-sourcemaps@^1.0.5:
18401840
dependencies:
18411841
source-map "^0.6.1"
18421842

1843-
connection-string@^3.1.0:
1844-
version "3.1.0"
1845-
resolved "https://registry.yarnpkg.com/connection-string/-/connection-string-3.1.0.tgz#459ac5cf04eb239ee179506c630be8ed3265218a"
1846-
integrity sha512-Gy+QoTYc09PqsrRoOZyKUYWL73ug/afVvQfRA3C5XIoYlm3TTUBAwjvOOP3AlGF3FHnZGY+nS98uKFjcj8RrPA==
1843+
connection-string@^3.1.1:
1844+
version "3.1.1"
1845+
resolved "https://registry.yarnpkg.com/connection-string/-/connection-string-3.1.1.tgz#871d81ec627ccc43eb8d621290e10a996598e733"
1846+
integrity sha512-d58cz9qYiz4lOw10EXjMadtElrb1TlPLDva5gwJELPzfJDe8MWEu10G6Y9ktgfMo8wP0LnREHjfGQr2ZEvbfcQ==
18471847

18481848
contains-path@^0.1.0:
18491849
version "0.1.0"
@@ -2395,10 +2395,10 @@ eslint-plugin-es@^3.0.0:
23952395
eslint-utils "^2.0.0"
23962396
regexpp "^3.0.0"
23972397

2398-
eslint-plugin-import@^2.20.0:
2399-
version "2.20.0"
2400-
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.20.0.tgz#d749a7263fb6c29980def8e960d380a6aa6aecaa"
2401-
integrity sha512-NK42oA0mUc8Ngn4kONOPsPB1XhbUvNHqF+g307dPV28aknPoiNnKLFd9em4nkswwepdF5ouieqv5Th/63U7YJQ==
2398+
eslint-plugin-import@^2.20.1:
2399+
version "2.20.1"
2400+
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.20.1.tgz#802423196dcb11d9ce8435a5fc02a6d3b46939b3"
2401+
integrity sha512-qQHgFOTjguR+LnYRoToeZWT62XM55MBVXObHM6SKFd1VzDcX/vqT1kAz8ssqigh5eMj8qXcRoXXGZpPP6RfdCw==
24022402
dependencies:
24032403
array-includes "^3.0.3"
24042404
array.prototype.flat "^1.2.1"
@@ -4935,10 +4935,15 @@ pg-int8@1.0.1:
49354935
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
49364936
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==
49374937

4938-
pg-pool@^2.0.7:
4939-
version "2.0.8"
4940-
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.8.tgz#f6d8c1727707cebcb1c50d0b1b770e0a031bf831"
4941-
integrity sha512-UE4H+4PT53RbwYaGxkeVDcMcp1g8EmYo91qeUugijsHwzV/RDpYVRWzmfiDisEQZhVDzyf/GUctNOrh+ZPJCGA==
4938+
pg-packet-stream@^1.1.0:
4939+
version "1.1.0"
4940+
resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914"
4941+
integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg==
4942+
4943+
pg-pool@^2.0.10:
4944+
version "2.0.10"
4945+
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a"
4946+
integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg==
49424947

49434948
pg-types@^2.1.0:
49444949
version "2.2.0"
@@ -4951,15 +4956,16 @@ pg-types@^2.1.0:
49514956
postgres-date "~1.0.4"
49524957
postgres-interval "^1.1.0"
49534958

4954-
pg@^7.15.1:
4955-
version "7.15.1"
4956-
resolved "https://registry.yarnpkg.com/pg/-/pg-7.15.1.tgz#a0bac84ebaeb809f3a369fb695ae89b314b08b22"
4957-
integrity sha512-o293Pxx5bNRpTv3Dh4+IIhPbTw19Bo4zvppLgR+MAV2I7AF3sMr9gPB4JPvBffWb24pDfC+7Ghe6xh2VxVMBpQ==
4959+
pg@^7.18.2:
4960+
version "7.18.2"
4961+
resolved "https://registry.yarnpkg.com/pg/-/pg-7.18.2.tgz#4e219f05a00aff4db6aab1ba02f28ffa4513b0bb"
4962+
integrity sha512-Mvt0dGYMwvEADNKy5PMQGlzPudKcKKzJds/VbOeZJpb6f/pI3mmoXX0JksPgI3l3JPP/2Apq7F36O63J7mgveA==
49584963
dependencies:
49594964
buffer-writer "2.0.0"
49604965
packet-reader "1.0.0"
49614966
pg-connection-string "0.1.3"
4962-
pg-pool "^2.0.7"
4967+
pg-packet-stream "^1.1.0"
4968+
pg-pool "^2.0.10"
49634969
pg-types "^2.1.0"
49644970
pgpass "1.x"
49654971
semver "4.3.2"
@@ -5809,6 +5815,13 @@ rimraf@^3.0.0:
58095815
dependencies:
58105816
glob "^7.1.3"
58115817

5818+
rimraf@^3.0.2:
5819+
version "3.0.2"
5820+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a"
5821+
integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==
5822+
dependencies:
5823+
glob "^7.1.3"
5824+
58125825
rollup-plugin-babel@^4.3.2:
58135826
version "4.3.3"
58145827
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa"

0 commit comments

Comments
 (0)