diff --git a/src/lib/db/feature-tag-store.ts b/src/lib/db/feature-tag-store.ts index 8e3d787e74..e62a898506 100644 --- a/src/lib/db/feature-tag-store.ts +++ b/src/lib/db/feature-tag-store.ts @@ -71,8 +71,18 @@ class FeatureTagStore { return tag; } + /** + * Only gets tags for active feature toggles. + */ async getAllFeatureTags(): Promise { - const rows = await this.db(TABLE).select(COLUMNS); + const rows = await this.db(TABLE) + .select(COLUMNS) + .whereIn( + 'feature_name', + this.db('features') + .where({ archived: false }) + .select(['name']), + ); return rows.map(row => ({ featureName: row.feature_name, tagType: row.tag_type, diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index bd3f9e76cf..e2d16c0a21 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -112,11 +112,23 @@ class ProjectStore { .onConflict('id') .ignore(); if (rows.length > 0) { + await this.addGlobalEnvironment(rows); return rows.map(this.mapRow); } return []; } + async addGlobalEnvironment(projects): Promise { + const environments = projects.map(p => ({ + project_id: p.id, + environment_name: ':global:', + })); + await this.db('project_environments') + .insert(environments) + .onConflict(['project_id', 'environment_name']) + .ignore(); + } + async dropProjects(): Promise { await this.db(TABLE).del(); } diff --git a/src/lib/services/state-service.ts b/src/lib/services/state-service.ts index 20e78e14eb..4b3659c7e4 100644 --- a/src/lib/services/state-service.ts +++ b/src/lib/services/state-service.ts @@ -161,11 +161,15 @@ export default class StateService { tagTypes: data.tagTypes, tags: data.tags, featureTags: - data.featureTags.map(t => ({ - featureName: t.featureName, - tagValue: t.tagValue || t.value, - tagType: t.tagType || t.type, - })) || [], + data.featureTags + .filter(t => + data.features.some(f => f.name === t.featureName), + ) + .map(t => ({ + featureName: t.featureName, + tagValue: t.tagValue || t.value, + tagType: t.tagType || t.type, + })) || [], userName, dropBeforeImport, keepExisting, @@ -522,7 +526,7 @@ export default class StateService { : Promise.resolve([]), includeTags ? this.tagTypeStore.getAll() : Promise.resolve([]), includeTags ? this.tagStore.getAll() : Promise.resolve([]), - includeTags + includeTags && includeFeatureToggles ? this.featureTagStore.getAllFeatureTags() : Promise.resolve([]), includeFeatureToggles