fix: avoid history data loss when license is missing (#23562)

* fix: avoid history data loss when license is missing

* fix: history lifecycle test

* fix: restore ts-expect-error
This commit is contained in:
Rémi de Juvigny 2025-05-27 18:24:14 +02:00 committed by GitHub
parent dd588fdca6
commit 883f4fcabd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -21,7 +21,11 @@ const mockGetRequestContext = jest.fn(() => {
}); });
const mockStrapi = { const mockStrapi = {
service: jest.fn(), service: jest.fn((name: string) => {
if (name === 'admin::persist-tables') {
return { persistTablesWithPrefix: jest.fn() };
}
}),
plugins: { plugins: {
'content-manager': { 'content-manager': {
service: jest.fn(() => ({ service: jest.fn(() => ({
@ -81,9 +85,9 @@ describe('history lifecycles service', () => {
jest.useRealTimers(); jest.useRealTimers();
}); });
it('inits service only once', () => { it('inits service only once', async () => {
lifecyclesService.bootstrap(); await lifecyclesService.bootstrap();
lifecyclesService.bootstrap(); await lifecyclesService.bootstrap();
// @ts-expect-error - ignore // @ts-expect-error - ignore
expect(mockStrapi.documents.use).toHaveBeenCalledTimes(1); expect(mockStrapi.documents.use).toHaveBeenCalledTimes(1);
}); });

View File

@ -101,6 +101,7 @@ const createLifecyclesService = ({ strapi }: { strapi: Core.Strapi }) => {
}; };
const serviceUtils = createServiceUtils({ strapi }); const serviceUtils = createServiceUtils({ strapi });
const { persistTablesWithPrefix } = strapi.service('admin::persist-tables');
return { return {
async bootstrap() { async bootstrap() {
@ -109,6 +110,9 @@ const createLifecyclesService = ({ strapi }: { strapi: Core.Strapi }) => {
return; return;
} }
// Avoid data loss in case users temporarily don't have a license
await persistTablesWithPrefix('strapi_history_versions');
strapi.documents.use(async (context, next) => { strapi.documents.use(async (context, next) => {
const result = (await next()) as any; const result = (await next()) as any;