mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 14:19:40 +00:00
Merge branch 'main' into chore/tracking-edit-field-name
This commit is contained in:
commit
a45e27372a
7
.github/actions/install-modules/action.yml
vendored
7
.github/actions/install-modules/action.yml
vendored
@ -1,12 +1,7 @@
|
|||||||
name: 'Install modules'
|
name: 'Install modules'
|
||||||
description: 'Run yarn install and add global modules'
|
description: 'Install yarn dependencies'
|
||||||
inputs:
|
|
||||||
globalPackages:
|
|
||||||
description: 'Global packages to install'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
- run: $GITHUB_ACTION_PATH/script.sh
|
- run: $GITHUB_ACTION_PATH/script.sh
|
||||||
env:
|
|
||||||
GLOBAL_PACKAGES: ${{ inputs.globalPackages }}
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
6
.github/actions/install-modules/script.sh
vendored
6
.github/actions/install-modules/script.sh
vendored
@ -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
|
# run yarn
|
||||||
yarn
|
yarn
|
||||||
|
|||||||
1
.github/workflows/db/postgres/init.sql
vendored
Normal file
1
.github/workflows/db/postgres/init.sql
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE SCHEMA myschema;
|
||||||
26
.github/workflows/tests.yml
vendored
26
.github/workflows/tests.yml
vendored
@ -34,8 +34,6 @@ jobs:
|
|||||||
name: 'unit_back (node: ${{ matrix.node }})'
|
name: 'unit_back (node: ${{ matrix.node }})'
|
||||||
needs: [lint]
|
needs: [lint]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
CODECOV_TOKEN: ${{ secrets.codecov }}
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: [14, 16, 18]
|
node: [14, 16, 18]
|
||||||
@ -46,17 +44,19 @@ jobs:
|
|||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- uses: ./.github/actions/install-modules
|
- uses: ./.github/actions/install-modules
|
||||||
with:
|
|
||||||
globalPackages: codecov
|
|
||||||
- name: Run tests
|
- 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:
|
unit_front:
|
||||||
name: 'unit_front (node: ${{ matrix.node }})'
|
name: 'unit_front (node: ${{ matrix.node }})'
|
||||||
needs: [lint]
|
needs: [lint]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
CODECOV_TOKEN: ${{ secrets.codecov }}
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node: [14, 16, 18]
|
node: [14, 16, 18]
|
||||||
@ -67,12 +67,16 @@ jobs:
|
|||||||
node-version: ${{ matrix.node }}
|
node-version: ${{ matrix.node }}
|
||||||
cache: yarn
|
cache: yarn
|
||||||
- uses: ./.github/actions/install-modules
|
- uses: ./.github/actions/install-modules
|
||||||
with:
|
|
||||||
globalPackages: codecov
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: yarn build
|
run: yarn build
|
||||||
- name: Run test
|
- 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:
|
api_ce_pg:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -96,6 +100,7 @@ jobs:
|
|||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
-v /__w/.github/workflows/db/postgres:/docker-entrypoint-initdb.d
|
||||||
ports:
|
ports:
|
||||||
# Maps tcp port 5432 on service container to the host
|
# Maps tcp port 5432 on service container to the host
|
||||||
- 5432:5432
|
- 5432:5432
|
||||||
@ -226,6 +231,7 @@ jobs:
|
|||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
-v /__w/.github/workflows/db/postgres:/docker-entrypoint-initdb.d
|
||||||
ports:
|
ports:
|
||||||
# Maps tcp port 5432 on service container to the host
|
# Maps tcp port 5432 on service container to the host
|
||||||
- 5432:5432
|
- 5432:5432
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -68,6 +68,7 @@ $RECYCLE.BIN/
|
|||||||
.tmp
|
.tmp
|
||||||
*.log
|
*.log
|
||||||
*.sql
|
*.sql
|
||||||
|
!.github/workflows/db/**/*.sql
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
coverageDirectory: '<rootDir>/coverage',
|
||||||
projects: ['<rootDir>/packages/**/jest.config.js', '<rootDir>/.github'],
|
projects: ['<rootDir>/packages/**/jest.config.js', '<rootDir>/.github'],
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,5 +8,4 @@ module.exports = {
|
|||||||
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
||||||
roots: [__dirname],
|
roots: [__dirname],
|
||||||
collectCoverageFrom: ['<rootDir>/packages/core/admin/admin/**/*.js'],
|
collectCoverageFrom: ['<rootDir>/packages/core/admin/admin/**/*.js'],
|
||||||
coverageDirectory: '<rootDir>/packages/core/admin/coverage',
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const {
|
|||||||
hasInverseOrderColumn,
|
hasInverseOrderColumn,
|
||||||
} = require('../metadata/relations');
|
} = require('../metadata/relations');
|
||||||
const { createQueryBuilder } = require('../query');
|
const { createQueryBuilder } = require('../query');
|
||||||
|
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.
|
* 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);
|
.transacting(trx);
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
|
const joinTableName = addSchema(joinTable.name);
|
||||||
await db.connection
|
await db.connection
|
||||||
.raw(
|
.raw(
|
||||||
`UPDATE ?? as a
|
`UPDATE ?? as a
|
||||||
@ -252,9 +254,10 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|||||||
WHERE ${where.join(' OR ')}
|
WHERE ${where.join(' OR ')}
|
||||||
) AS b
|
) AS b
|
||||||
WHERE b.id = a.id`,
|
WHERE b.id = a.id`,
|
||||||
[joinTable.name, ...updateBinding, ...selectBinding, joinTable.name, ...whereBinding]
|
[joinTableName, ...updateBinding, ...selectBinding, joinTableName, ...whereBinding]
|
||||||
)
|
)
|
||||||
.transacting(trx);
|
.transacting(trx);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
`UPDATE :joinTable: as a
|
`UPDATE :joinTable: as a
|
||||||
SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order
|
SET :orderColumn: = b.src_order, :inverseOrderColumn: = b.inv_order
|
||||||
|
|||||||
@ -7,6 +7,16 @@ const isKnexQuery = (value) => {
|
|||||||
return value instanceof KnexBuilder || value instanceof KnexRaw;
|
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 = {
|
module.exports = {
|
||||||
isKnexQuery,
|
isKnexQuery,
|
||||||
|
addSchema,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,5 +6,4 @@ module.exports = {
|
|||||||
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
|
||||||
roots: [__dirname],
|
roots: [__dirname],
|
||||||
collectCoverageFrom: ['<rootDir>/packages/core/helper-plugin/lib/src/**/*.js'],
|
collectCoverageFrom: ['<rootDir>/packages/core/helper-plugin/lib/src/**/*.js'],
|
||||||
coverageDirectory: '<rootDir>/packages/core/helper-plugin/coverage',
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -154,7 +154,7 @@ module.exports = {
|
|||||||
|
|
||||||
// update path for folders themselves & folders below
|
// update path for folders themselves & folders below
|
||||||
totalFolderNumber = await strapi.db
|
totalFolderNumber = await strapi.db
|
||||||
.connection(folderTable)
|
.getConnection(folderTable)
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where(pathColName, existingFolder.path)
|
.where(pathColName, existingFolder.path)
|
||||||
.orWhere(pathColName, 'like', `${existingFolder.path}/%`)
|
.orWhere(pathColName, 'like', `${existingFolder.path}/%`)
|
||||||
@ -169,7 +169,7 @@ module.exports = {
|
|||||||
|
|
||||||
// update path of files below
|
// update path of files below
|
||||||
totalFileNumber = await strapi.db
|
totalFileNumber = await strapi.db
|
||||||
.connection(fileTable)
|
.getConnection(fileTable)
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where(folderPathColName, existingFolder.path)
|
.where(folderPathColName, existingFolder.path)
|
||||||
.orWhere(folderPathColName, 'like', `${existingFolder.path}/%`)
|
.orWhere(folderPathColName, 'like', `${existingFolder.path}/%`)
|
||||||
@ -209,7 +209,7 @@ module.exports = {
|
|||||||
|
|
||||||
// update files main fields (path + updatedBy)
|
// update files main fields (path + updatedBy)
|
||||||
await strapi.db
|
await strapi.db
|
||||||
.connection(fileTable)
|
.getConnection(fileTable)
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.whereIn('id', fileIds)
|
.whereIn('id', fileIds)
|
||||||
.update(folderPathColName, destinationFolderPath);
|
.update(folderPathColName, destinationFolderPath);
|
||||||
|
|||||||
@ -41,7 +41,7 @@ describe('metrics', () => {
|
|||||||
metadata: {
|
metadata: {
|
||||||
get: () => ({ attributes: { path: { columnName: 'path' } } }),
|
get: () => ({ attributes: { path: { columnName: 'path' } } }),
|
||||||
},
|
},
|
||||||
connection() {
|
getConnection() {
|
||||||
return {
|
return {
|
||||||
select() {
|
select() {
|
||||||
return {
|
return {
|
||||||
@ -53,7 +53,7 @@ describe('metrics', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
strapi.db.connection.raw = raw;
|
strapi.db.connection = { raw };
|
||||||
|
|
||||||
const { computeMetrics } = metricsService({ strapi });
|
const { computeMetrics } = metricsService({ strapi });
|
||||||
|
|
||||||
|
|||||||
@ -147,7 +147,7 @@ const update = async (id, { name, parent }, { user }) => {
|
|||||||
|
|
||||||
// update folders below
|
// update folders below
|
||||||
await strapi.db
|
await strapi.db
|
||||||
.connection(folderTable)
|
.getConnection(folderTable)
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where(pathColumnName, existingFolder.path)
|
.where(pathColumnName, existingFolder.path)
|
||||||
.orWhere(pathColumnName, 'like', `${existingFolder.path}/%`)
|
.orWhere(pathColumnName, 'like', `${existingFolder.path}/%`)
|
||||||
@ -162,7 +162,7 @@ const update = async (id, { name, parent }, { user }) => {
|
|||||||
|
|
||||||
// update files below
|
// update files below
|
||||||
await strapi.db
|
await strapi.db
|
||||||
.connection(fileTable)
|
.getConnection(fileTable)
|
||||||
.transacting(trx)
|
.transacting(trx)
|
||||||
.where(folderPathColumnName, existingFolder.path)
|
.where(folderPathColumnName, existingFolder.path)
|
||||||
.orWhere(folderPathColumnName, 'like', `${existingFolder.path}/%`)
|
.orWhere(folderPathColumnName, 'like', `${existingFolder.path}/%`)
|
||||||
|
|||||||
@ -27,8 +27,6 @@ module.exports = ({ strapi }) => ({
|
|||||||
queryParams.push(String(i), '');
|
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 following query goal is to count the number of folders with depth 1, depth 2 etc.
|
||||||
The query returns :
|
The query returns :
|
||||||
@ -49,9 +47,10 @@ module.exports = ({ strapi }) => ({
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const folderLevelsArray = (
|
const folderLevelsArray = (
|
||||||
await knex(folderTable)
|
await strapi.db
|
||||||
|
.getConnection(folderTable)
|
||||||
.select(
|
.select(
|
||||||
knex.raw(
|
strapi.db.connection.raw(
|
||||||
`LENGTH(${keepOnlySlashesSQLString}) AS depth, COUNT(*) AS occurence`,
|
`LENGTH(${keepOnlySlashesSQLString}) AS depth, COUNT(*) AS occurence`,
|
||||||
queryParams
|
queryParams
|
||||||
)
|
)
|
||||||
|
|||||||
@ -18,6 +18,7 @@ const batchInsertInTmpTable = async ({ updatesInfo }, { transacting: trx }) => {
|
|||||||
const updateFromTmpTable = async ({ model, attributesToMigrate }, { transacting: trx }) => {
|
const updateFromTmpTable = async ({ model, attributesToMigrate }, { transacting: trx }) => {
|
||||||
const { collectionName } = model;
|
const { collectionName } = model;
|
||||||
if (model.client === 'pg') {
|
if (model.client === 'pg') {
|
||||||
|
// IMPORTANT TODO: use postgres schema
|
||||||
const substitutes = attributesToMigrate.map(() => '?? = ??.??').join(',');
|
const substitutes = attributesToMigrate.map(() => '?? = ??.??').join(',');
|
||||||
const bindings = [collectionName];
|
const bindings = [collectionName];
|
||||||
attributesToMigrate.forEach((attr) => bindings.push(attr, TMP_TABLE_NAME, attr));
|
attributesToMigrate.forEach((attr) => bindings.push(attr, TMP_TABLE_NAME, attr));
|
||||||
|
|||||||
@ -20,6 +20,7 @@ const databases = {
|
|||||||
database: 'strapi_test',
|
database: 'strapi_test',
|
||||||
username: 'strapi',
|
username: 'strapi',
|
||||||
password: 'strapi',
|
password: 'strapi',
|
||||||
|
schema: 'myschema',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mysql: {
|
mysql: {
|
||||||
|
|||||||
@ -16,6 +16,7 @@ const databases = {
|
|||||||
database: 'strapi_test',
|
database: 'strapi_test',
|
||||||
username: 'strapi',
|
username: 'strapi',
|
||||||
password: 'strapi',
|
password: 'strapi',
|
||||||
|
schema: 'myschema',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mysql: {
|
mysql: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user