mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
efd47b72a8
## 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>
54 lines
2.3 KiB
JavaScript
54 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
exports.up = function (db, callback) {
|
|
db.runSql(
|
|
`
|
|
ALTER TABLE feature_environments ADD COLUMN variants JSONB DEFAULT '[]'::jsonb NOT NULL;
|
|
WITH feature_variants AS (SELECT variants, name FROM features)
|
|
UPDATE feature_environments SET variants = feature_variants.variants FROM feature_variants WHERE feature_name = feature_variants.name;
|
|
|
|
CREATE VIEW features_view AS
|
|
SELECT
|
|
features.name as name,
|
|
features.description as description,
|
|
features.type as type,
|
|
features.project as project,
|
|
features.stale as stale,
|
|
feature_environments.variants as variants,
|
|
features.impression_data as impression_data,
|
|
features.created_at as created_at,
|
|
features.last_seen_at as last_seen_at,
|
|
features.archived_at as archived_at,
|
|
feature_environments.enabled as enabled,
|
|
feature_environments.environment as environment,
|
|
environments.name as environment_name,
|
|
environments.type as environment_type,
|
|
environments.sort_order as environment_sort_order,
|
|
feature_strategies.id as strategy_id,
|
|
feature_strategies.strategy_name as strategy_name,
|
|
feature_strategies.parameters as parameters,
|
|
feature_strategies.constraints as constraints,
|
|
feature_strategies.sort_order as sort_order,
|
|
fss.segment_id as segments
|
|
FROM
|
|
features
|
|
LEFT JOIN feature_environments ON feature_environments.feature_name = features.name
|
|
LEFT JOIN feature_strategies ON feature_strategies.feature_name = feature_environments.feature_name
|
|
and feature_strategies.environment = feature_environments.environment
|
|
LEFT JOIN environments ON feature_environments.environment = environments.name
|
|
LEFT JOIN feature_strategy_segment as fss ON fss.feature_strategy_id = feature_strategies.id;
|
|
`,
|
|
callback,
|
|
);
|
|
};
|
|
|
|
exports.down = function (db, callback) {
|
|
db.runSql(
|
|
`
|
|
DROP VIEW features_view;
|
|
ALTER TABLE feature_environments DROP COLUMN variants;
|
|
`,
|
|
callback,
|
|
);
|
|
};
|