From dc73beb0b042a8009006b7c6def60685083dbc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Zed=C3=A9n=20Yver=C3=A5s?= Date: Mon, 10 Jun 2024 13:59:30 +0200 Subject: [PATCH 1/3] Rename `appuser` to `dbowner` As noted in #215, the naming `appuser` may confuse users into thinking the account to use for DATABASE_URL is the same as the account that should be used by the application to connect to the database. While this may be true in some setups, it is not a hard requirement (see the discussion in #215 for further details). resolves #215 --- README.md | 10 +++++----- __tests__/settings.test.ts | 18 +++++++++--------- src/commands/init.ts | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0bf3ec6..fc7685f 100644 --- a/README.md +++ b/README.md @@ -108,9 +108,9 @@ unaffected by the iteration you've been applying to your development database Create your database role (if desired), database and shadow database: ```bash -createuser --pwprompt appuser -createdb myapp --owner=appuser -createdb myapp_shadow --owner=appuser +createuser --pwprompt dbowner +createdb myapp --owner=dbowner +createdb myapp_shadow --owner=dbowner ``` Export your database URL, shadow database URL, and a "root" database URL which @@ -119,8 +119,8 @@ PostgreSQL servers have a default database called `postgres` which is a good choice for this). ```bash -export DATABASE_URL="postgres://appuser:password@localhost/myapp" -export SHADOW_DATABASE_URL="postgres://appuser:password@localhost/myapp_shadow" +export DATABASE_URL="postgres://dbowner:password@localhost/myapp" +export SHADOW_DATABASE_URL="postgres://dbowner:password@localhost/myapp_shadow" export ROOT_DATABASE_URL="postgres://postgres:postgres@localhost/postgres" ``` diff --git a/__tests__/settings.test.ts b/__tests__/settings.test.ts index 5d71a55..94b55a6 100644 --- a/__tests__/settings.test.ts +++ b/__tests__/settings.test.ts @@ -320,12 +320,12 @@ describe("gmrc path", () => { mockFs.restore(); mockFs({ [DEFAULT_GMRC_PATH]: ` - { "connectionString": "postgres://appuser:apppassword@host:5432/defaultdb" } + { "connectionString": "postgres://dbowner:password@host:5432/defaultdb" } `, }); const settings = await getSettings(); expect(settings.connectionString).toEqual( - "postgres://appuser:apppassword@host:5432/defaultdb", + "postgres://dbowner:password@host:5432/defaultdb", ); mockFs.restore(); }); @@ -334,15 +334,15 @@ describe("gmrc path", () => { mockFs.restore(); mockFs({ [DEFAULT_GMRC_PATH]: ` - { "connectionString": "postgres://appuser:apppassword@host:5432/defaultdb" } + { "connectionString": "postgres://dbowner:password@host:5432/defaultdb" } `, ".other-gmrc": ` - { "connectionString": "postgres://appuser:apppassword@host:5432/otherdb" } + { "connectionString": "postgres://dbowner:password@host:5432/otherdb" } `, }); const settings = await getSettings({ configFile: ".other-gmrc" }); expect(settings.connectionString).toEqual( - "postgres://appuser:apppassword@host:5432/otherdb", + "postgres://dbowner:password@host:5432/otherdb", ); mockFs.restore(); }); @@ -362,12 +362,12 @@ describe("gmrc from JS", () => { mockFs({ [DEFAULT_GMRCJS_PATH]: /* JavaScript */ `\ module.exports = { - connectionString: "postgres://appuser:apppassword@host:5432/gmrcjs_test", + connectionString: "postgres://dbowner:password@host:5432/gmrcjs_test", };`, }); const settings = await getSettings(); expect(settings.connectionString).toEqual( - "postgres://appuser:apppassword@host:5432/gmrcjs_test", + "postgres://dbowner:password@host:5432/gmrcjs_test", ); mockFs.restore(); }); @@ -382,12 +382,12 @@ module.exports = { mockFs({ [DEFAULT_GMRC_COMMONJS_PATH]: /* JavaScript */ `\ module.exports = { - connectionString: "postgres://appuser:apppassword@host:5432/gmrc_commonjs_test", + connectionString: "postgres://dbowner:password@host:5432/gmrc_commonjs_test", };`, }); const settings = await getSettings(); expect(settings.connectionString).toEqual( - "postgres://appuser:apppassword@host:5432/gmrc_commonjs_test", + "postgres://dbowner:password@host:5432/gmrc_commonjs_test", ); mockFs.restore(); }); diff --git a/src/commands/init.ts b/src/commands/init.ts index b617c30..7df09b4 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -46,7 +46,7 @@ export async function init(options: InitArgv = {}): Promise { * * RECOMMENDATION: use \`DATABASE_URL\` envvar instead. */ - // "connectionString": "postgres://appuser:apppassword@host:5432/appdb", + // "connectionString": "postgres://dbowner:password@host:5432/appdb", /* * shadowConnectionString: like connectionString, but this is used for the @@ -54,7 +54,7 @@ export async function init(options: InitArgv = {}): Promise { * * RECOMMENDATION: use \`SHADOW_DATABASE_URL\` envvar instead. */ - // "shadowConnectionString": "postgres://appuser:apppassword@host:5432/appdb_shadow", + // "shadowConnectionString": "postgres://dbowner:password@host:5432/appdb_shadow", /* * rootConnectionString: like connectionString, but this is used for From 9d8047f3134f2be53ef6695d606918b5c3718fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Zed=C3=A9n=20Yver=C3=A5s?= Date: Mon, 10 Jun 2024 14:05:56 +0200 Subject: [PATCH 2/3] docs: add reference to issue #215 when discussing database roles resolves #215 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fc7685f..7244bd8 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,10 @@ createdb myapp --owner=dbowner createdb myapp_shadow --owner=dbowner ``` +> For an in depth-discussion on the different users and roles typically +> involved in database and migration management, please see issue +> [#215](https://github.com/graphile/migrate/issues/215). + Export your database URL, shadow database URL, and a "root" database URL which should be a superuser account connection to any **other** database (most PostgreSQL servers have a default database called `postgres` which is a good From d1771bb74301c799ad3320adf2d94ae202bbc693 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 12 Jun 2024 14:26:59 +0100 Subject: [PATCH 3/3] Prettier --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7244bd8..ae6ec50 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ createdb myapp --owner=dbowner createdb myapp_shadow --owner=dbowner ``` -> For an in depth-discussion on the different users and roles typically -> involved in database and migration management, please see issue +> For an in depth-discussion on the different users and roles typically involved +> in database and migration management, please see issue > [#215](https://github.com/graphile/migrate/issues/215). Export your database URL, shadow database URL, and a "root" database URL which