File tree Expand file tree Collapse file tree 6 files changed +52
-12
lines changed Expand file tree Collapse file tree 6 files changed +52
-12
lines changed Original file line number Diff line number Diff line change 1
1
import { Request , Response } from "express" ;
2
2
import { ExecutionResult , graphql , GraphQLSchema } from "graphql" ;
3
3
import { Pool , PoolClient } from "pg" ;
4
+ import { parse } from "pg-connection-string" ;
4
5
import {
5
6
createPostGraphileSchema ,
6
7
PostGraphileOptions ,
@@ -105,9 +106,7 @@ interface ICtx {
105
106
let ctx : ICtx | null = null ;
106
107
107
108
export const setup = async ( ) => {
108
- const rootPgPool = new Pool ( {
109
- connectionString : process . env . TEST_DATABASE_URL ,
110
- } ) ;
109
+ const rootPgPool = new Pool ( parse ( process . env . TEST_DATABASE_URL ) as any ) ;
111
110
112
111
const options = getPostGraphileOptions ( { rootPgPool } ) ;
113
112
const schema = await createPostGraphileSchema (
Original file line number Diff line number Diff line change 39
39
"passport" : " ^0.4.1" ,
40
40
"passport-github2" : " ^0.1.11" ,
41
41
"pg" : " ^8.0.3" ,
42
+ "pg-connection-string" : " ^2.2.0" ,
42
43
"postgraphile" : " ^4.7.0" ,
43
44
"redis" : " ^3.0.2" ,
44
45
"source-map-support" : " ^0.5.13" ,
Original file line number Diff line number Diff line change 1
1
import { Express } from "express" ;
2
2
import { Pool } from "pg" ;
3
+ import { parse } from "pg-connection-string" ;
3
4
4
5
import { getShutdownActions } from "../app" ;
5
6
@@ -25,16 +26,12 @@ function swallowPoolError(_error: Error) {
25
26
26
27
export default ( app : Express ) => {
27
28
// This pool runs as the database owner, so it can do anything.
28
- const rootPgPool = new Pool ( {
29
- connectionString : process . env . DATABASE_URL ,
30
- } ) ;
29
+ const rootPgPool = new Pool ( parse ( process . env . DATABASE_URL ! ) as any ) ;
31
30
rootPgPool . on ( "error" , swallowPoolError ) ;
32
31
app . set ( "rootPgPool" , rootPgPool ) ;
33
32
34
33
// This pool runs as the unprivileged user, it's what PostGraphile uses.
35
- const authPgPool = new Pool ( {
36
- connectionString : process . env . AUTH_DATABASE_URL ,
37
- } ) ;
34
+ const authPgPool = new Pool ( parse ( process . env . AUTH_DATABASE_URL ! ) as any ) ;
38
35
authPgPool . on ( "error" , swallowPoolError ) ;
39
36
app . set ( "authPgPool" , authPgPool ) ;
40
37
Original file line number Diff line number Diff line change 3
3
"private" : true ,
4
4
"version" : " 0.0.0" ,
5
5
"scripts" : {
6
- "gw" : " cd dist && node -r @app/config/env ../node_modules/.bin/graphile-worker " ,
6
+ "gw" : " node -r @app/config/env dist/index.js " ,
7
7
"build" : " tsc -b" ,
8
8
"start" : " yarn gw" ,
9
- "dev" : " cd dist && node -r @app/config/env --inspect=9757 ../node_modules/.bin/graphile-worker --watch" ,
9
+ "dev" : " node -r @app/config/env --inspect=9757 dist/index.js --watch" ,
10
10
"install-db-schema" : " mkdir -p dist && yarn gw --schema-only"
11
11
},
12
12
"dependencies" : {
22
22
"lodash" : " ^4.17.15" ,
23
23
"mjml" : " ^4.6.2" ,
24
24
"nodemailer" : " ^6.4.6" ,
25
+ "pg" : " ^8.0.3" ,
26
+ "pg-connection-string" : " ^2.2.0" ,
25
27
"tslib" : " ^1.11.1"
26
28
}
27
29
}
Original file line number Diff line number Diff line change
1
+ import { getTasks , run , runMigrations } from "graphile-worker" ;
2
+ import { Pool } from "pg" ;
3
+ import { parse } from "pg-connection-string" ;
4
+
5
+ /*
6
+ * Normally you'd use the CLI, but we need to use pg-connection-string >= 2.1.0,
7
+ * and pg only uses 0.1.3 so we have to drop to library mode.
8
+ */
9
+
10
+ async function main ( ) {
11
+ const pgPool = new Pool ( parse ( process . env . DATABASE_URL ! ) as any ) ;
12
+ try {
13
+ const options = { pgPool } ;
14
+ const schemaOnly = process . argv . includes ( "--schema-only" ) ;
15
+ if ( schemaOnly ) {
16
+ return await runMigrations ( options ) ;
17
+ }
18
+ const watch = process . argv . includes ( "--watch" ) ;
19
+ const { tasks, release } = await getTasks (
20
+ options ,
21
+ `${ __dirname } /tasks` ,
22
+ watch
23
+ ) ;
24
+ try {
25
+ const { promise } = await run ( {
26
+ ...options ,
27
+ taskList : tasks ,
28
+ } ) ;
29
+ return await promise ;
30
+ } finally {
31
+ release ( ) ;
32
+ }
33
+ } finally {
34
+ pgPool . end ( ) ;
35
+ }
36
+ }
37
+
38
+ main ( ) . catch ( ( err ) => {
39
+ console . error ( err ) ;
40
+ process . exit ( 1 ) ;
41
+ } ) ;
Original file line number Diff line number Diff line change 12329
12329
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-0.1.3.tgz#da1847b20940e42ee1492beaf65d49d91b245df7"
12330
12330
integrity sha1-2hhHsglA5C7hSSvq9l1J2RskXfc=
12331
12331
12332
- pg-connection-string@^2.0.0, pg-connection-string@^2.1.0:
12332
+ pg-connection-string@^2.0.0, pg-connection-string@^2.1.0, pg-connection-string@^2.2.0 :
12333
12333
version "2.2.0"
12334
12334
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.2.0.tgz#caab4d38a9de4fdc29c9317acceed752897de41c"
12335
12335
integrity sha512-xB/+wxcpFipUZOQcSzcgkjcNOosGhEoPSjz06jC89lv1dj7mc9bZv6wLVy8M2fVjP0a/xN0N988YDq1L0FhK3A==
You can’t perform that action at this time.
0 commit comments