Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15719 from strapi/fix/audit-log-table
Rename audit logs table name
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/core/admin/ee/server/migrations/audit-logs-table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters