mirror of
https://github.com/strapi/strapi.git
synced 2025-09-01 04:42:58 +00:00
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:
parent
dd588fdca6
commit
883f4fcabd
@ -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);
|
||||||
});
|
});
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user