put add-schema in knex util file

This commit is contained in:
Pierre Noël 2022-11-19 00:01:10 +01:00
parent edc34137c4
commit 6a530cbbfc
3 changed files with 11 additions and 11 deletions

View File

@ -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.

View File

@ -1,10 +0,0 @@
'use strict';
const addSchema = (tableName) => {
const schemaName = strapi.db.connection.getSchemaName();
return schemaName ? `${schemaName}.${tableName}` : tableName;
};
module.exports = {
addSchema,
};

View File

@ -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,
};