mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-15 01:16:22 +02:00
feat: backfill archived features lifecycle (#8824)
This commit is contained in:
parent
f8ae7fd539
commit
5c7f4d5fc1
@ -35,6 +35,14 @@ export class FeatureLifecycleStore implements IFeatureLifecycleStore {
|
|||||||
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature
|
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature
|
||||||
WHERE feature_lifecycles.feature IS NULL
|
WHERE feature_lifecycles.feature IS NULL
|
||||||
`);
|
`);
|
||||||
|
await this.db.raw(`
|
||||||
|
INSERT INTO feature_lifecycles (feature, stage, created_at)
|
||||||
|
SELECT features.name, 'archived', features.archived_at
|
||||||
|
FROM features
|
||||||
|
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature AND feature_lifecycles.stage = 'archived'
|
||||||
|
WHERE features.archived_at IS NOT NULL
|
||||||
|
AND feature_lifecycles.feature IS NULL
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async insert(
|
async insert(
|
||||||
|
@ -192,19 +192,50 @@ test('should be able to toggle between completed/uncompleted', async () => {
|
|||||||
expect(body).toEqual([]);
|
expect(body).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should backfill initial stage when no stages', async () => {
|
test('should backfill intialized feature', async () => {
|
||||||
await app.createFeature('my_feature_c');
|
await app.createFeature('my_feature_c');
|
||||||
|
|
||||||
await featureLifecycleStore.delete('my_feature_c');
|
await featureLifecycleStore.delete('my_feature_c');
|
||||||
|
|
||||||
const currentStage = await getCurrentStage('my_feature_c');
|
|
||||||
expect(currentStage).toBe(undefined);
|
|
||||||
|
|
||||||
await featureLifecycleStore.backfill();
|
await featureLifecycleStore.backfill();
|
||||||
|
|
||||||
const backfilledCurrentStage = await getCurrentStage('my_feature_c');
|
const { body } = await getFeatureLifecycle('my_feature_c');
|
||||||
expect(backfilledCurrentStage).toEqual({
|
expect(body).toEqual([
|
||||||
stage: 'initial',
|
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
||||||
enteredStageAt: expect.any(Date),
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should backfill archived feature', async () => {
|
||||||
|
await app.createFeature('my_feature_d');
|
||||||
|
await app.archiveFeature('my_feature_d');
|
||||||
|
await featureLifecycleStore.delete('my_feature_d');
|
||||||
|
|
||||||
|
await featureLifecycleStore.backfill();
|
||||||
|
|
||||||
|
const { body } = await getFeatureLifecycle('my_feature_d');
|
||||||
|
expect(body).toEqual([
|
||||||
|
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
||||||
|
{ stage: 'archived', enteredStageAt: expect.any(String) },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not backfill for existing lifecycle', async () => {
|
||||||
|
await app.createFeature('my_feature_e');
|
||||||
|
await app.enableFeature('my_feature_e', 'default');
|
||||||
|
eventStore.emit(FEATURE_CREATED, { featureName: 'my_feature_e' });
|
||||||
|
eventBus.emit(CLIENT_METRICS_ADDED, [
|
||||||
|
{
|
||||||
|
featureName: 'my_feature_e',
|
||||||
|
environment: 'default',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
await reachedStage('my_feature_e', 'live');
|
||||||
|
|
||||||
|
await featureLifecycleStore.backfill();
|
||||||
|
|
||||||
|
const { body } = await getFeatureLifecycle('my_feature_e');
|
||||||
|
expect(body).toEqual([
|
||||||
|
{ stage: 'initial', enteredStageAt: expect.any(String) },
|
||||||
|
{ stage: 'pre-live', enteredStageAt: expect.any(String) },
|
||||||
|
{ stage: 'live', enteredStageAt: expect.any(String) },
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user