From a9276c78c194acb485443631aba2b91a6704fe64 Mon Sep 17 00:00:00 2001 From: Joel Low Date: Thu, 1 Oct 2020 10:39:37 +0800 Subject: [PATCH] Remove role creation logic --- .../backend-common/src/database/postgres.ts | 36 ++----------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/packages/backend-common/src/database/postgres.ts b/packages/backend-common/src/database/postgres.ts index bd8a9670cf..6f7f706811 100644 --- a/packages/backend-common/src/database/postgres.ts +++ b/packages/backend-common/src/database/postgres.ts @@ -30,7 +30,7 @@ export async function createPgDatabaseClient( overrides?: knex.Config, ) { const baseConfig = buildPgDatabaseConfig(dbConfig, overrides); - let knexConfig = baseConfig; + const knexConfig = baseConfig; // Bootstrap the missing database. if (!!baseConfig?.connection.database) { @@ -38,10 +38,6 @@ export async function createPgDatabaseClient( const admin = knex(knexAdminConfig); await ensurePgDatabase(admin, baseConfig.connection.database); - knexConfig = buildPgPluginConfig( - cloneDeep(baseConfig), - baseConfig.connection.database, - ); } const database = knex(knexConfig); @@ -81,18 +77,6 @@ function buildPgDatabaseAdminConfig(dbConfig: JsonValue) { }); } -/** - * Builds a knex Postgres database connection for plugin consumption - * - * @param dbConfig The database config - * @param database The database granted to the plugin - */ -function buildPgPluginConfig(dbConfig: JsonValue, database: string) { - return mergeDatabaseConfig(dbConfig, { - connection: roleCredentials(database), - }); -} - /** * Gets the Postgres connection config * @@ -133,23 +117,7 @@ async function ensurePgDatabase(admin: knex, database: string) { return; } - const owner = roleCredentials(database); - await admin.raw(`CREATE ROLE ?? WITH LOGIN PASSWORD '${owner.password}'`, [ - owner.user, - ]); - await admin.raw(`CREATE DATABASE ?? OWNER ??`, [database, owner.user]); -} - -/** - * Creates credentials to own the given database - * - * @param database The name of the database to create a role for - */ -function roleCredentials(database: string) { - return { - user: database, - password: database, - }; + await admin.raw(`CREATE DATABASE ??`, [database]); } /**