From d7f51f3431cf2401a0759477b31c1f6bf9beaac9 Mon Sep 17 00:00:00 2001 From: hos Date: Tue, 15 Oct 2024 22:23:02 +0400 Subject: [PATCH 1/3] Replace `template1` with `postgres:///template1` --- __tests__/__snapshots__/settings.test.ts.snap | 10 +++++----- __tests__/actions.test.ts | 4 +++- __tests__/settings.test.ts | 4 ++-- src/settings.ts | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/__tests__/__snapshots__/settings.test.ts.snap b/__tests__/__snapshots__/settings.test.ts.snap index 0e33092..68d7da5 100644 --- a/__tests__/__snapshots__/settings.test.ts.snap +++ b/__tests__/__snapshots__/settings.test.ts.snap @@ -38,7 +38,7 @@ exports[`actions is backwards-compatible with untagged command specs 1`] = ` "manageGraphileMigrateSchema": true, "migrationsFolder": "./migrations", "placeholders": undefined, - "rootConnectionString": "template1", + "rootConnectionString": "postgres:///template1", "shadowConnectionString": undefined, "shadowDatabaseName": undefined, } @@ -79,7 +79,7 @@ exports[`actions parses SQL actions 1`] = ` "manageGraphileMigrateSchema": true, "migrationsFolder": "./migrations", "placeholders": undefined, - "rootConnectionString": "template1", + "rootConnectionString": "postgres:///template1", "shadowConnectionString": undefined, "shadowDatabaseName": undefined, } @@ -115,7 +115,7 @@ exports[`actions parses command actions 1`] = ` "manageGraphileMigrateSchema": true, "migrationsFolder": "./migrations", "placeholders": undefined, - "rootConnectionString": "template1", + "rootConnectionString": "postgres:///template1", "shadowConnectionString": undefined, "shadowDatabaseName": undefined, } @@ -159,7 +159,7 @@ exports[`actions parses mixed actions 1`] = ` "manageGraphileMigrateSchema": true, "migrationsFolder": "./migrations", "placeholders": undefined, - "rootConnectionString": "template1", + "rootConnectionString": "postgres:///template1", "shadowConnectionString": undefined, "shadowDatabaseName": undefined, } @@ -200,7 +200,7 @@ exports[`actions parses string values into SQL actions 1`] = ` "manageGraphileMigrateSchema": true, "migrationsFolder": "./migrations", "placeholders": undefined, - "rootConnectionString": "template1", + "rootConnectionString": "postgres:///template1", "shadowConnectionString": undefined, "shadowDatabaseName": undefined, } diff --git a/__tests__/actions.test.ts b/__tests__/actions.test.ts index 110f131..86a2297 100644 --- a/__tests__/actions.test.ts +++ b/__tests__/actions.test.ts @@ -93,7 +93,9 @@ it("runs sql afterReset action with correct connection string when root", async mockedWithClient.mockClear(); await executeActions(parsedSettings, false, parsedSettings.afterReset); expect(mockedWithClient).toHaveBeenCalledTimes(1); - expect(mockedWithClient.mock.calls[0][0]).toBe(TEST_DATABASE_NAME); + expect(mockedWithClient.mock.calls[0][0]).toBe( + `postgres:///${TEST_DATABASE_NAME}`, + ); }); it("runs command afterReset action with correct env vars when root", async () => { diff --git a/__tests__/settings.test.ts b/__tests__/settings.test.ts index 94b55a6..ffa8757 100644 --- a/__tests__/settings.test.ts +++ b/__tests__/settings.test.ts @@ -362,12 +362,12 @@ describe("gmrc from JS", () => { mockFs({ [DEFAULT_GMRCJS_PATH]: /* JavaScript */ `\ module.exports = { - connectionString: "postgres://dbowner:password@host:5432/gmrcjs_test", + connectionString: "postgres:///dbowner:password@host:5432/gmrcjs_test", };`, }); const settings = await getSettings(); expect(settings.connectionString).toEqual( - "postgres://dbowner:password@host:5432/gmrcjs_test", + "postgres:///dbowner:password@host:5432/gmrcjs_test", ); mockFs.restore(); }); diff --git a/src/settings.ts b/src/settings.ts index 97ae7c0..79e665e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -157,7 +157,8 @@ export async function parseSettings( const rootConnectionString = await check( "rootConnectionString", ( - rawRootConnectionString = process.env.ROOT_DATABASE_URL || "template1", + rawRootConnectionString = process.env.ROOT_DATABASE_URL || + "postgres:///template1", ): string => { if (typeof rawRootConnectionString !== "string") { throw new Error( From 307327863c7189bdd168ec1f2bc83ae2d8006d0b Mon Sep 17 00:00:00 2001 From: Benjie Date: Wed, 16 Oct 2024 10:49:05 +0100 Subject: [PATCH 2/3] Apply suggestions from code review --- __tests__/settings.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/settings.test.ts b/__tests__/settings.test.ts index ffa8757..8e5c67c 100644 --- a/__tests__/settings.test.ts +++ b/__tests__/settings.test.ts @@ -362,7 +362,7 @@ describe("gmrc from JS", () => { mockFs({ [DEFAULT_GMRCJS_PATH]: /* JavaScript */ `\ module.exports = { - connectionString: "postgres:///dbowner:password@host:5432/gmrcjs_test", + connectionString: "postgres://dbowner:password@host:5432/gmrcjs_test", };`, }); const settings = await getSettings(); From f5c1e20632729aebf6976f9adfb3c29e66b1c938 Mon Sep 17 00:00:00 2001 From: Benjie Date: Wed, 16 Oct 2024 10:49:32 +0100 Subject: [PATCH 3/3] Update __tests__/settings.test.ts --- __tests__/settings.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/settings.test.ts b/__tests__/settings.test.ts index 8e5c67c..94b55a6 100644 --- a/__tests__/settings.test.ts +++ b/__tests__/settings.test.ts @@ -367,7 +367,7 @@ module.exports = { }); const settings = await getSettings(); expect(settings.connectionString).toEqual( - "postgres:///dbowner:password@host:5432/gmrcjs_test", + "postgres://dbowner:password@host:5432/gmrcjs_test", ); mockFs.restore(); });