chore: improve naming of persisted tables

This commit is contained in:
Jamie Howard 2023-03-17 13:31:55 +00:00
parent 1ae35507fe
commit b17dd81556
3 changed files with 16 additions and 16 deletions

View File

@ -5,7 +5,7 @@ const { features } = require('@strapi/strapi/lib/utils/ee');
const executeCEBootstrap = require('../../server/bootstrap');
const { getService } = require('../../server/utils');
const actions = require('./config/admin-actions');
const { reserveTablesWithPrefix } = require('./utils/reserved-tables');
const { persistTablesWithPrefix } = require('./utils/persisted-tables');
module.exports = async () => {
const { actionProvider } = getService('permission');
@ -15,7 +15,7 @@ module.exports = async () => {
}
if (features.isEnabled('audit-logs')) {
await reserveTablesWithPrefix('strapi_audit_logs');
await persistTablesWithPrefix('strapi_audit_logs');
await actionProvider.registerMany(actions.auditLogs);
}

View File

@ -14,36 +14,36 @@ const findTablesThatStartWithPrefix = async (prefix) => {
* Get all reserved table names from the core store
* @returns {Array}
*/
const getReservedTables = async () =>
const getPersistedTables = async () =>
strapi.store.get({
type: 'core',
key: 'reserved_tables',
});
key: 'persisted_tables',
}) ?? [];
/**
* Add all table names that start with a prefix to the reserved tables in
* core store
* @param {string} tableNamePrefix
*/
const reserveTablesWithPrefix = async (tableNamePrefix) => {
const reservedTables = (await getReservedTables()) || [];
const persistTablesWithPrefix = async (tableNamePrefix) => {
const persistedTables = (await getPersistedTables()) || [];
const tableNames = await findTablesThatStartWithPrefix(tableNamePrefix);
const notReservedTableNames = tableNames.filter((name) => !persistedTables.includes(name));
if (!tableNames.length) {
if (!notReservedTableNames.length) {
return;
}
reservedTables.push(...tableNames.filter((name) => !reservedTables.includes(name)));
persistedTables.push(...notReservedTableNames);
await strapi.store.set({
type: 'core',
key: 'reserved_tables',
value: reservedTables,
key: 'persisted_tables',
value: persistedTables,
});
};
module.exports = {
reserveTablesWithPrefix,
persistTablesWithPrefix,
findTablesThatStartWithPrefix,
};

View File

@ -345,10 +345,10 @@ module.exports = (db) => {
}
const persistedTables = helpers.hasTable(srcSchema, 'strapi_core_store_settings')
? await strapi.store.get({
? (await strapi.store.get({
type: 'core',
key: 'reserved_tables',
})
key: 'persisted_tables',
})) ?? []
: [];
for (const srcTable of srcSchema.tables) {