1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: backfill archived features lifecycle (#8824)

This commit is contained in:
Mateusz Kwasniewski 2024-11-21 14:41:20 +01:00 committed by GitHub
parent f8ae7fd539
commit 5c7f4d5fc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 10 deletions

View File

@ -35,6 +35,14 @@ export class FeatureLifecycleStore implements IFeatureLifecycleStore {
LEFT JOIN feature_lifecycles ON features.name = feature_lifecycles.feature
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(

View File

@ -192,19 +192,50 @@ test('should be able to toggle between completed/uncompleted', async () => {
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 featureLifecycleStore.delete('my_feature_c');
const currentStage = await getCurrentStage('my_feature_c');
expect(currentStage).toBe(undefined);
await featureLifecycleStore.backfill();
const backfilledCurrentStage = await getCurrentStage('my_feature_c');
expect(backfilledCurrentStage).toEqual({
stage: 'initial',
enteredStageAt: expect.any(Date),
});
const { body } = await getFeatureLifecycle('my_feature_c');
expect(body).toEqual([
{ stage: 'initial', enteredStageAt: expect.any(String) },
]);
});
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) },
]);
});