1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

fix: only import feature_tags for imported features

This commit is contained in:
Christopher Kolstad 2021-07-30 13:38:28 +02:00
parent b1c8fea5c6
commit 9646bcfebb
No known key found for this signature in database
GPG Key ID: 559ACB0E3DB5538A
3 changed files with 33 additions and 7 deletions

View File

@ -71,8 +71,18 @@ class FeatureTagStore {
return tag; return tag;
} }
/**
* Only gets tags for active feature toggles.
*/
async getAllFeatureTags(): Promise<IFeatureTag[]> { async getAllFeatureTags(): Promise<IFeatureTag[]> {
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 => ({ return rows.map(row => ({
featureName: row.feature_name, featureName: row.feature_name,
tagType: row.tag_type, tagType: row.tag_type,

View File

@ -112,11 +112,23 @@ class ProjectStore {
.onConflict('id') .onConflict('id')
.ignore(); .ignore();
if (rows.length > 0) { if (rows.length > 0) {
await this.addGlobalEnvironment(rows);
return rows.map(this.mapRow); return rows.map(this.mapRow);
} }
return []; return [];
} }
async addGlobalEnvironment(projects): Promise<void> {
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<void> { async dropProjects(): Promise<void> {
await this.db(TABLE).del(); await this.db(TABLE).del();
} }

View File

@ -161,7 +161,11 @@ export default class StateService {
tagTypes: data.tagTypes, tagTypes: data.tagTypes,
tags: data.tags, tags: data.tags,
featureTags: featureTags:
data.featureTags.map(t => ({ data.featureTags
.filter(t =>
data.features.some(f => f.name === t.featureName),
)
.map(t => ({
featureName: t.featureName, featureName: t.featureName,
tagValue: t.tagValue || t.value, tagValue: t.tagValue || t.value,
tagType: t.tagType || t.type, tagType: t.tagType || t.type,
@ -522,7 +526,7 @@ export default class StateService {
: Promise.resolve([]), : Promise.resolve([]),
includeTags ? this.tagTypeStore.getAll() : Promise.resolve([]), includeTags ? this.tagTypeStore.getAll() : Promise.resolve([]),
includeTags ? this.tagStore.getAll() : Promise.resolve([]), includeTags ? this.tagStore.getAll() : Promise.resolve([]),
includeTags includeTags && includeFeatureToggles
? this.featureTagStore.getAllFeatureTags() ? this.featureTagStore.getAllFeatureTags()
: Promise.resolve([]), : Promise.resolve([]),
includeFeatureToggles includeFeatureToggles