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

View File

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