From 9ff4f1966002343e6ff0337259f2316033267671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 10:08:49 +0100 Subject: [PATCH 01/13] fix schema support for postgres when using raw queries --- .../database/lib/entity-manager/regular-relations.js | 7 +++++-- packages/core/database/lib/utils/add-schema.js | 10 ++++++++++ .../upload/server/controllers/admin-folder-file.js | 6 +++--- packages/core/upload/server/services/folder.js | 4 ++-- packages/core/upload/server/services/metrics.js | 7 +++---- .../server/migrations/field/migrate-for-bookshelf.js | 1 + 6 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 packages/core/database/lib/utils/add-schema.js diff --git a/packages/core/database/lib/entity-manager/regular-relations.js b/packages/core/database/lib/entity-manager/regular-relations.js index 7b1e69ce04..27bd70dbf2 100644 --- a/packages/core/database/lib/entity-manager/regular-relations.js +++ b/packages/core/database/lib/entity-manager/regular-relations.js @@ -10,6 +10,7 @@ const { hasInverseOrderColumn, } = require('../metadata/relations'); const { createQueryBuilder } = require('../query'); +const { addSchema } = require('../utils/add-schema'); /** * If some relations currently exist for this oneToX relation, on the one side, this function removes them and update the inverse order if needed. @@ -241,7 +242,8 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction ) .transacting(trx); break; - default: + default: { + const joinTableName = addSchema(joinTable.name); await db.connection .raw( `UPDATE ?? as a @@ -252,9 +254,10 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction WHERE ${where.join(' OR ')} ) AS b WHERE b.id = a.id`, - [joinTable.name, ...updateBinding, ...selectBinding, joinTable.name, ...whereBinding] + [joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding] ) .transacting(trx); + } /* `UPDATE :joinTable: as a SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order diff --git a/packages/core/database/lib/utils/add-schema.js b/packages/core/database/lib/utils/add-schema.js new file mode 100644 index 0000000000..a6daaa09d9 --- /dev/null +++ b/packages/core/database/lib/utils/add-schema.js @@ -0,0 +1,10 @@ +'use strict'; + +const addSchema = (tableName) => { + const schemaName = strapi.db.connection.getSchemaName(); + return schemaName ? `${schemaName}.${tableName}` : tableName; +}; + +module.export = { + addSchema, +}; diff --git a/packages/core/upload/server/controllers/admin-folder-file.js b/packages/core/upload/server/controllers/admin-folder-file.js index c17a7ba739..d3597e88bc 100644 --- a/packages/core/upload/server/controllers/admin-folder-file.js +++ b/packages/core/upload/server/controllers/admin-folder-file.js @@ -154,7 +154,7 @@ module.exports = { // update path for folders themselves & folders below totalFolderNumber = await strapi.db - .connection(folderTable) + .getConnection(folderTable) .transacting(trx) .where(pathColName, existingFolder.path) .orWhere(pathColName, 'like', `${existingFolder.path}/%`) @@ -169,7 +169,7 @@ module.exports = { // update path of files below totalFileNumber = await strapi.db - .connection(fileTable) + .getConnection(fileTable) .transacting(trx) .where(folderPathColName, existingFolder.path) .orWhere(folderPathColName, 'like', `${existingFolder.path}/%`) @@ -209,7 +209,7 @@ module.exports = { // update files main fields (path + updatedBy) await strapi.db - .connection(fileTable) + .getConnection(fileTable) .transacting(trx) .whereIn('id', fileIds) .update(folderPathColName, destinationFolderPath); diff --git a/packages/core/upload/server/services/folder.js b/packages/core/upload/server/services/folder.js index e6741f9b39..cf31d95485 100644 --- a/packages/core/upload/server/services/folder.js +++ b/packages/core/upload/server/services/folder.js @@ -147,7 +147,7 @@ const update = async (id, { name, parent }, { user }) => { // update folders below await strapi.db - .connection(folderTable) + .getConnection(folderTable) .transacting(trx) .where(pathColumnName, existingFolder.path) .orWhere(pathColumnName, 'like', `${existingFolder.path}/%`) @@ -162,7 +162,7 @@ const update = async (id, { name, parent }, { user }) => { // update files below await strapi.db - .connection(fileTable) + .getConnection(fileTable) .transacting(trx) .where(folderPathColumnName, existingFolder.path) .orWhere(folderPathColumnName, 'like', `${existingFolder.path}/%`) diff --git a/packages/core/upload/server/services/metrics.js b/packages/core/upload/server/services/metrics.js index 2b9e2a13c4..c20ca46165 100644 --- a/packages/core/upload/server/services/metrics.js +++ b/packages/core/upload/server/services/metrics.js @@ -27,8 +27,6 @@ module.exports = ({ strapi }) => ({ queryParams.push(String(i), ''); } - const knex = strapi.db.connection; - /* The following query goal is to count the number of folders with depth 1, depth 2 etc. The query returns : @@ -49,9 +47,10 @@ module.exports = ({ strapi }) => ({ */ const folderLevelsArray = ( - await knex(folderTable) + await strapi.db + .getConnection(folderTable) .select( - knex.raw( + strapi.db.connection.raw( `LENGTH(${keepOnlySlashesSQLString}) AS depth, COUNT(*) AS occurence`, queryParams ) diff --git a/packages/plugins/i18n/server/migrations/field/migrate-for-bookshelf.js b/packages/plugins/i18n/server/migrations/field/migrate-for-bookshelf.js index fbe7385a70..fc4c4dd2ea 100644 --- a/packages/plugins/i18n/server/migrations/field/migrate-for-bookshelf.js +++ b/packages/plugins/i18n/server/migrations/field/migrate-for-bookshelf.js @@ -18,6 +18,7 @@ const batchInsertInTmpTable = async ({ updatesInfo }, { transacting: trx }) => { const updateFromTmpTable = async ({ model, attributesToMigrate }, { transacting: trx }) => { const { collectionName } = model; if (model.client === 'pg') { + // IMPORTANT TODO: use postgres schema const substitutes = attributesToMigrate.map(() => '?? = ??.??').join(','); const bindings = [collectionName]; attributesToMigrate.forEach((attr) => bindings.push(attr, TMP_TABLE_NAME, attr)); From b4295cf5218121bf7b764a7514c7c89004ad2617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 11:41:12 +0100 Subject: [PATCH 02/13] fix typo --- packages/core/database/lib/utils/add-schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/database/lib/utils/add-schema.js b/packages/core/database/lib/utils/add-schema.js index a6daaa09d9..356aa77ab7 100644 --- a/packages/core/database/lib/utils/add-schema.js +++ b/packages/core/database/lib/utils/add-schema.js @@ -5,6 +5,6 @@ const addSchema = (tableName) => { return schemaName ? `${schemaName}.${tableName}` : tableName; }; -module.export = { +module.exports = { addSchema, }; From 82b2cd4805cbfc218c7fe0b594b0ea834e580a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 12:01:09 +0100 Subject: [PATCH 03/13] fix unit tests --- packages/core/upload/server/services/__tests__/metrics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/upload/server/services/__tests__/metrics.js b/packages/core/upload/server/services/__tests__/metrics.js index 7fafdd80cf..956e86648d 100644 --- a/packages/core/upload/server/services/__tests__/metrics.js +++ b/packages/core/upload/server/services/__tests__/metrics.js @@ -41,7 +41,7 @@ describe('metrics', () => { metadata: { get: () => ({ attributes: { path: { columnName: 'path' } } }), }, - connection() { + getConnection() { return { select() { return { @@ -53,7 +53,7 @@ describe('metrics', () => { }, }, }; - strapi.db.connection.raw = raw; + strapi.db.connection = { raw }; const { computeMetrics } = metricsService({ strapi }); From d31da5b4aeae9a35cc71db3046aa85f448249886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 12:24:58 +0100 Subject: [PATCH 04/13] add a postgres schema for api tests --- test/create-test-app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/create-test-app.js b/test/create-test-app.js index 9df9bd9cec..ebd5b09ead 100644 --- a/test/create-test-app.js +++ b/test/create-test-app.js @@ -16,6 +16,7 @@ const databases = { database: 'strapi_test', username: 'strapi', password: 'strapi', + schema: 'myschema', }, }, mysql: { From c45a4c37534b6a273cde7503155fb30bbad2936d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 12:52:31 +0100 Subject: [PATCH 05/13] add a postgres schema for tests in .github --- .github/workflows/db/postgres/init.sql | 1 + .github/workflows/tests.yml | 4 ++++ .gitignore | 1 + 3 files changed, 6 insertions(+) create mode 100644 .github/workflows/db/postgres/init.sql diff --git a/.github/workflows/db/postgres/init.sql b/.github/workflows/db/postgres/init.sql new file mode 100644 index 0000000000..138887e817 --- /dev/null +++ b/.github/workflows/db/postgres/init.sql @@ -0,0 +1 @@ +CREATE SCHEMA myschema; diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1edbefcfa..676f2a8387 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -99,6 +99,8 @@ jobs: ports: # Maps tcp port 5432 on service container to the host - 5432:5432 + volumes: + - ./db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -229,6 +231,8 @@ jobs: ports: # Maps tcp port 5432 on service container to the host - 5432:5432 + volumes: + - ./db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 diff --git a/.gitignore b/.gitignore index b9472f751b..06d74047d7 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ $RECYCLE.BIN/ .tmp *.log *.sql +!.github/workflows/db/**/*.sql *.sqlite From 055e008539efbe18b5ae1941a03bf096b42c26d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 13:23:11 +0100 Subject: [PATCH 06/13] remove semi-colomn --- .github/workflows/db/postgres/init.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/db/postgres/init.sql b/.github/workflows/db/postgres/init.sql index 138887e817..446a15ae45 100644 --- a/.github/workflows/db/postgres/init.sql +++ b/.github/workflows/db/postgres/init.sql @@ -1 +1 @@ -CREATE SCHEMA myschema; +CREATE SCHEMA myschema From e95269c4616e6de1a191822344652994a179c0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 13:30:23 +0100 Subject: [PATCH 07/13] fix init script path --- .github/workflows/db/postgres/init.sql | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/db/postgres/init.sql b/.github/workflows/db/postgres/init.sql index 446a15ae45..138887e817 100644 --- a/.github/workflows/db/postgres/init.sql +++ b/.github/workflows/db/postgres/init.sql @@ -1 +1 @@ -CREATE SCHEMA myschema +CREATE SCHEMA myschema; diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 676f2a8387..2162d6c137 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -232,7 +232,7 @@ jobs: # Maps tcp port 5432 on service container to the host - 5432:5432 volumes: - - ./db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + - ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 From 3296be986172d1963111fb3c5a7ce3bca91003ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 23:07:30 +0100 Subject: [PATCH 08/13] set volumes in options --- .github/workflows/tests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2162d6c137..36c4d615f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -96,11 +96,10 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + -v ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql ports: # Maps tcp port 5432 on service container to the host - 5432:5432 - volumes: - - ./db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 @@ -228,11 +227,10 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + -v ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql ports: # Maps tcp port 5432 on service container to the host - 5432:5432 - volumes: - - ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 From 08fbbd166c9240eb12e295775b74c9f0a41bbc34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Thu, 17 Nov 2022 23:42:55 +0100 Subject: [PATCH 09/13] use absolute path --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36c4d615f3..7fa6a9ea89 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -96,7 +96,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - -v ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + -v /__w/.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql ports: # Maps tcp port 5432 on service container to the host - 5432:5432 @@ -227,7 +227,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - -v ./.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + -v /__w/.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql ports: # Maps tcp port 5432 on service container to the host - 5432:5432 From edc34137c4476613c98ab1cb866a68e4d75acb97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Fri, 18 Nov 2022 00:59:44 +0100 Subject: [PATCH 10/13] use directory instead of file --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7fa6a9ea89..c494854f99 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -96,7 +96,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - -v /__w/.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + -v /__w/.github/workflows/db/postgres:/docker-entrypoint-initdb.d ports: # Maps tcp port 5432 on service container to the host - 5432:5432 @@ -227,7 +227,7 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - -v /__w/.github/workflows/db/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql + -v /__w/.github/workflows/db/postgres:/docker-entrypoint-initdb.d ports: # Maps tcp port 5432 on service container to the host - 5432:5432 From 2c23ca234bc820be9cc7f4cafa9289a1b6aa9bc1 Mon Sep 17 00:00:00 2001 From: Gustav Hansen Date: Mon, 14 Nov 2022 13:53:00 +0100 Subject: [PATCH 11/13] Chore: Update codecov uploader --- .github/actions/install-modules/action.yml | 7 +----- .github/actions/install-modules/script.sh | 6 ----- .github/workflows/tests.yml | 24 +++++++++++-------- jest.config.js | 1 + packages/core/admin/jest.config.front.js | 1 - .../core/helper-plugin/jest.config.front.js | 1 - 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.github/actions/install-modules/action.yml b/.github/actions/install-modules/action.yml index 2767ac53f7..73e6826b46 100644 --- a/.github/actions/install-modules/action.yml +++ b/.github/actions/install-modules/action.yml @@ -1,12 +1,7 @@ name: 'Install modules' -description: 'Run yarn install and add global modules' -inputs: - globalPackages: - description: 'Global packages to install' +description: 'Install yarn dependencies' runs: using: 'composite' steps: - run: $GITHUB_ACTION_PATH/script.sh - env: - GLOBAL_PACKAGES: ${{ inputs.globalPackages }} shell: bash diff --git a/.github/actions/install-modules/script.sh b/.github/actions/install-modules/script.sh index 4f66899c59..f4a3806144 100755 --- a/.github/actions/install-modules/script.sh +++ b/.github/actions/install-modules/script.sh @@ -1,8 +1,2 @@ -# install global packages if set -if [[ -n "$GLOBAL_PACKAGES" ]]; then - yarn global add "$GLOBAL_PACKAGES" - yarn global bin >>$GITHUB_PATH -fi - # run yarn yarn diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 82b5a50644..57d84cd366 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,8 +34,6 @@ jobs: name: 'unit_back (node: ${{ matrix.node }})' needs: [lint] runs-on: ubuntu-latest - env: - CODECOV_TOKEN: ${{ secrets.codecov }} strategy: matrix: node: [14, 16, 18] @@ -46,17 +44,19 @@ jobs: node-version: ${{ matrix.node }} cache: yarn - uses: ./.github/actions/install-modules - with: - globalPackages: codecov - name: Run tests - run: yarn run -s test:unit --coverage && codecov -C -F unit + run: yarn run -s test:unit --coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage + flags: back,unit_back unit_front: name: 'unit_front (node: ${{ matrix.node }})' needs: [lint] runs-on: ubuntu-latest - env: - CODECOV_TOKEN: ${{ secrets.codecov }} strategy: matrix: node: [14, 16, 18] @@ -67,12 +67,16 @@ jobs: node-version: ${{ matrix.node }} cache: yarn - uses: ./.github/actions/install-modules - with: - globalPackages: codecov - name: Build run: yarn build - name: Run test - run: yarn run -s test:front --coverage && codecov -C -F front + run: yarn run -s test:front --coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage + flags: front,unit_front api_ce_pg: runs-on: ubuntu-latest diff --git a/jest.config.js b/jest.config.js index 7c265e8ca7..85b9798b19 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ 'use strict'; module.exports = { + coverageDirectory: '/coverage', projects: ['/packages/**/jest.config.js', '/.github'], }; diff --git a/packages/core/admin/jest.config.front.js b/packages/core/admin/jest.config.front.js index 3c3bd59d20..7e4e322bb7 100644 --- a/packages/core/admin/jest.config.front.js +++ b/packages/core/admin/jest.config.front.js @@ -8,5 +8,4 @@ module.exports = { displayName: (pkg.strapi && pkg.strapi.name) || pkg.name, roots: [__dirname], collectCoverageFrom: ['/packages/core/admin/admin/**/*.js'], - coverageDirectory: '/packages/core/admin/coverage', }; diff --git a/packages/core/helper-plugin/jest.config.front.js b/packages/core/helper-plugin/jest.config.front.js index a2fb1019e7..e0c3ffe921 100644 --- a/packages/core/helper-plugin/jest.config.front.js +++ b/packages/core/helper-plugin/jest.config.front.js @@ -6,5 +6,4 @@ module.exports = { displayName: (pkg.strapi && pkg.strapi.name) || pkg.name, roots: [__dirname], collectCoverageFrom: ['/packages/core/helper-plugin/lib/src/**/*.js'], - coverageDirectory: '/packages/core/helper-plugin/coverage', }; From 6a530cbbfc56a368dc97b61acaa9a6d58c192ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Sat, 19 Nov 2022 00:01:10 +0100 Subject: [PATCH 12/13] put add-schema in knex util file --- .../database/lib/entity-manager/regular-relations.js | 2 +- packages/core/database/lib/utils/add-schema.js | 10 ---------- packages/core/database/lib/utils/knex.js | 10 ++++++++++ 3 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 packages/core/database/lib/utils/add-schema.js diff --git a/packages/core/database/lib/entity-manager/regular-relations.js b/packages/core/database/lib/entity-manager/regular-relations.js index 27bd70dbf2..0174cae83b 100644 --- a/packages/core/database/lib/entity-manager/regular-relations.js +++ b/packages/core/database/lib/entity-manager/regular-relations.js @@ -10,7 +10,7 @@ const { hasInverseOrderColumn, } = require('../metadata/relations'); const { createQueryBuilder } = require('../query'); -const { addSchema } = require('../utils/add-schema'); +const { addSchema } = require('../utils/knex'); /** * If some relations currently exist for this oneToX relation, on the one side, this function removes them and update the inverse order if needed. diff --git a/packages/core/database/lib/utils/add-schema.js b/packages/core/database/lib/utils/add-schema.js deleted file mode 100644 index 356aa77ab7..0000000000 --- a/packages/core/database/lib/utils/add-schema.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -const addSchema = (tableName) => { - const schemaName = strapi.db.connection.getSchemaName(); - return schemaName ? `${schemaName}.${tableName}` : tableName; -}; - -module.exports = { - addSchema, -}; diff --git a/packages/core/database/lib/utils/knex.js b/packages/core/database/lib/utils/knex.js index 9e437d71c5..3306b37672 100644 --- a/packages/core/database/lib/utils/knex.js +++ b/packages/core/database/lib/utils/knex.js @@ -7,6 +7,16 @@ const isKnexQuery = (value) => { return value instanceof KnexBuilder || value instanceof KnexRaw; }; +/** + * Adds the name of the schema to the table name if the schema was defined by the user. + * Users can set the db schema only for Postgres in strapi database config. + */ +const addSchema = (tableName) => { + const schemaName = strapi.db.connection.getSchemaName(); + return schemaName ? `${schemaName}.${tableName}` : tableName; +}; + module.exports = { isKnexQuery, + addSchema, }; From fc26a070147d53d981f3884adf1bb1719afa61f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Sat, 19 Nov 2022 01:04:54 +0100 Subject: [PATCH 13/13] add schema in api.js file --- test/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/api.js b/test/api.js index 572e8e0df8..e3341236e7 100644 --- a/test/api.js +++ b/test/api.js @@ -20,6 +20,7 @@ const databases = { database: 'strapi_test', username: 'strapi', password: 'strapi', + schema: 'myschema', }, }, mysql: {