1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/packages/unleash-api/notes/schema.md
Ivar 0cb45f110c Add support for aggregate_strategies in the API.
This commit changes the features-tables:
- drop columns 'strategy' and 'parameters'
- add column 'strategies' of type json.
- migrates existing strategy-mappings in to the new format.

The idea is that the 'strategies' column should contain a json-array
of strategy-configuration for the toggle:

```
[{
 "name" : "strategy1",
 "parameters": { "name": "vale" }
}]

```

To make sure to not break exiting clients the api is extended with a
mapping layer (adding old fields to the json-respons, and mapping
to the new format on create/update a feature toggle.

this commit is first step in solving #102
2020-02-20 08:30:27 +01:00

3.5 KiB

Schema

Table: migrations

Used by db-migrate module to keep track of migrations.

NAME TYPE SIZE NULLABLE COLUMN_DEF
id serial 10 0 nextval('migrations_id_seq'::regclass)
name varchar 255 0 (null)
run_on timestamp 29 0 (null)

Table: events

NAME TYPE SIZE NULLABLE COLUMN_DEF
id serial 10 0 nextval('events_id_seq'::regclass)
created_at timestamp 29 1 now()
type varchar 255 0 (null)
created_by varchar 255 0 (null)
data json 2147483647 1 (null)

Table: _strategies_loc

NAME TYPE SIZE NULLABLE COLUMN_DEF
created_at timestamp 29 1 now()
name varchar 255 0 (null)
description text 2147483647 1 (null)
parameters_template json 2147483647 1 (null)

Table: features

NAME TYPE SIZE NULLABLE COLUMN_DEF COMMENT
created_at timestamp 29 1 now()
name varchar 255 0 (null)
enabled int4 10 1 0
description text 2147483647 1 (null)
archived int4 10 1 0
parameters json 2147483647 1 (null) deprecated (*)
strategy_name varchar 255 1 (null) deprecated (*)
strategies json 2147483647 1 (null)

(*) we migrated from parmaters and strategy_name to strategies which should contain an array of these.

For aggregate strategies we had the following sql to migrate to the strategies column:

ALTER TABLE features ADD "strategies" json;

--populate the strategies column
UPDATE features
SET strategies = ('[{"name":"'||f.strategy_name||'","parameters":'||f.parameters||'}]')::json
FROM features as f
WHERE f.name = features.name;

In order to migrate back, one can use the following sql (it will loose all, but the first activation strategy):

UPDATE features
SET strategy_name = f.strategies->0->>'name',
   parameters = f.strategies->0->'parameters'
FROM features as f
WHERE f.name = features.name;

ALTER TABLE features DROP COLUMN "strategies";