mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 00:09:18 +00:00
Merge pull request #15719 from strapi/fix/audit-log-table
Rename audit logs table name
This commit is contained in:
commit
2ecaa96419
45
packages/core/admin/ee/server/migrations/audit-logs-table.js
Normal file
45
packages/core/admin/ee/server/migrations/audit-logs-table.js
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Migrate the audit logs table name for users coming from v4.6.0
|
||||
*/
|
||||
async function migrateAuditLogsTable({ oldContentTypes, contentTypes }) {
|
||||
// Check if the audit logs table name was changed
|
||||
const oldName = oldContentTypes?.['admin::audit-log']?.collectionName;
|
||||
const newName = contentTypes['admin::audit-log']?.collectionName;
|
||||
const hasRenamedAuditLogsTable = oldName === 'audit_logs' && newName === 'strapi_audit_logs';
|
||||
|
||||
if (!hasRenamedAuditLogsTable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the previous audit log tables exist
|
||||
const hasAuditLogsTable = await strapi.db.getSchemaConnection().hasTable('audit_logs');
|
||||
const hasLinkTable = await strapi.db.getSchemaConnection().hasTable('audit_logs_user_links');
|
||||
|
||||
if (!hasAuditLogsTable || !hasLinkTable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the existing tables match the expected schema
|
||||
const auditLogsColumnInfo = await strapi.db.connection('audit_logs').columnInfo();
|
||||
const linkColumnInfo = await strapi.db.connection('audit_logs_user_links').columnInfo();
|
||||
|
||||
if (
|
||||
!auditLogsColumnInfo.action ||
|
||||
!auditLogsColumnInfo.date ||
|
||||
!auditLogsColumnInfo.payload ||
|
||||
!linkColumnInfo.audit_log_id ||
|
||||
!linkColumnInfo.user_id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the actual migrations
|
||||
await strapi.db.getSchemaConnection().renameTable('audit_logs', 'strapi_audit_logs');
|
||||
await strapi.db
|
||||
.getSchemaConnection()
|
||||
.renameTable('audit_logs_user_links', 'strapi_audit_logs_user_links');
|
||||
}
|
||||
|
||||
module.exports = migrateAuditLogsTable;
|
@ -2,10 +2,12 @@
|
||||
|
||||
const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||
const executeCERegister = require('../../server/register');
|
||||
const migrateAuditLogsTable = require('./migrations/audit-logs-table');
|
||||
const createAuditLogsService = require('./services/audit-logs');
|
||||
|
||||
module.exports = async ({ strapi }) => {
|
||||
if (features.isEnabled('audit-logs')) {
|
||||
strapi.hook('strapi::content-types.beforeSync').register(migrateAuditLogsTable);
|
||||
const auditLogsService = createAuditLogsService(strapi);
|
||||
strapi.container.register('audit-logs', auditLogsService);
|
||||
await auditLogsService.register();
|
||||
|
@ -75,6 +75,7 @@ describe('Audit logs service', () => {
|
||||
deleteMany: mockEntityServiceDeleteMany,
|
||||
},
|
||||
eventHub: createEventHub(),
|
||||
hook: () => ({ register: jest.fn() }),
|
||||
};
|
||||
|
||||
const mockSaveEvent = jest.fn();
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
module.exports = {
|
||||
kind: 'collectionType',
|
||||
collectionName: 'audit_logs',
|
||||
collectionName: 'strapi_audit_logs',
|
||||
info: {
|
||||
singularName: 'audit-log',
|
||||
pluralName: 'audit-logs',
|
||||
|
Loading…
x
Reference in New Issue
Block a user