mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	## About the changes Variants are now stored in each environment rather than in the feature toggle. This enables RBAC, suggest changes, etc to also apply to variants. Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: #2254 ### Important files - **src/lib/db/feature-strategy-store.ts** a complex query was moved to a view named `features_view` - **src/lib/services/state-service.ts** export version number increased due to the new format ## Discussion points We're keeping the old column as a safeguard to be able to go back Co-authored-by: sighphyre <liquidwicked64@gmail.com> Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
		
			
				
	
	
		
			71 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import joi from 'joi';
 | |
| import {
 | |
|     featureSchema,
 | |
|     featureTagSchema,
 | |
|     variantsSchema,
 | |
| } from '../schema/feature-schema';
 | |
| import strategySchema from './strategy-schema';
 | |
| import { tagSchema } from './tag-schema';
 | |
| import { tagTypeSchema } from './tag-type-schema';
 | |
| import { projectSchema } from './project-schema';
 | |
| import { nameType } from '../routes/util';
 | |
| import { featureStrategySegmentSchema, segmentSchema } from './segment-schema';
 | |
| 
 | |
| export const featureStrategySchema = joi
 | |
|     .object()
 | |
|     .keys({
 | |
|         id: joi.string().optional(),
 | |
|         featureName: joi.string(),
 | |
|         projectId: joi.string(),
 | |
|         environment: joi.string(),
 | |
|         parameters: joi.object().optional().allow(null),
 | |
|         constraints: joi.array().optional(),
 | |
|         strategyName: joi.string(),
 | |
|     })
 | |
|     .options({ stripUnknown: true });
 | |
| 
 | |
| export const featureEnvironmentsSchema = joi.object().keys({
 | |
|     environment: joi.string(),
 | |
|     featureName: joi.string(),
 | |
|     enabled: joi.boolean(),
 | |
|     variants: joi.array().items(variantsSchema).optional(),
 | |
| });
 | |
| 
 | |
| export const environmentSchema = joi.object().keys({
 | |
|     name: nameType,
 | |
|     displayName: joi.string().optional().allow(''),
 | |
|     type: joi.string().required(),
 | |
|     sortOrder: joi.number().optional(),
 | |
|     enabled: joi.boolean().optional(),
 | |
|     protected: joi.boolean().optional(),
 | |
| });
 | |
| 
 | |
| export const updateEnvironmentSchema = joi.object().keys({
 | |
|     displayName: joi.string().optional().allow(''),
 | |
|     type: joi.string().optional(),
 | |
|     sortOrder: joi.number().optional(),
 | |
| });
 | |
| 
 | |
| export const sortOrderSchema = joi.object().pattern(/^/, joi.number());
 | |
| 
 | |
| export const stateSchema = joi.object().keys({
 | |
|     version: joi.number(),
 | |
|     features: joi.array().optional().items(featureSchema),
 | |
|     strategies: joi.array().optional().items(strategySchema),
 | |
|     tags: joi.array().optional().items(tagSchema),
 | |
|     tagTypes: joi.array().optional().items(tagTypeSchema),
 | |
|     featureTags: joi.array().optional().items(featureTagSchema),
 | |
|     projects: joi.array().optional().items(projectSchema),
 | |
|     featureStrategies: joi.array().optional().items(featureStrategySchema),
 | |
|     featureEnvironments: joi
 | |
|         .array()
 | |
|         .optional()
 | |
|         .items(featureEnvironmentsSchema),
 | |
|     environments: joi.array().optional().items(environmentSchema),
 | |
|     segments: joi.array().optional().items(segmentSchema),
 | |
|     featureStrategySegments: joi
 | |
|         .array()
 | |
|         .optional()
 | |
|         .items(featureStrategySegmentSchema),
 | |
| });
 |