1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/migrations/20210105083014-add-tag-and-tag-types.js
Christopher Kolstad 43801f1f13
Add Tags and tag types
- First iteration of api for tags and tag-types
- Documentation in place
- Adds three new tables
   - tag_types
   - tags
   - feature_tag
- Tagging a feature is adding a row in the feature_tag
  join table

* #665

Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
2021-01-14 13:09:05 +01:00

42 lines
1.3 KiB
JavaScript

exports.up = function(db, cb) {
db.runSql(
`CREATE TABLE IF NOT EXISTS tag_types
(
name text PRIMARY KEY NOT NULL,
description text,
icon text,
created_at TIMESTAMP WITH TIME ZONE DEFAULT now()
);
CREATE TABLE IF NOT EXISTS tags
(
type text not null references tag_types (name) ON DELETE CASCADE,
value text,
created_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
PRIMARY KEY (type, value)
);
CREATE TABLE IF NOT EXISTS feature_tag
(
feature_name varchar(255) not null references features (name) ON DELETE CASCADE,
tag_type text not null,
tag_value text not null,
created_at TIMESTAMP WITH TIME ZONE DEFAULT now(),
UNIQUE (feature_name, tag_type, tag_value),
FOREIGN KEY (tag_type, tag_value) REFERENCES tags(type, value) ON DELETE CASCADE
);
INSERT INTO tag_types(name, description, icon)
VALUES ('simple', 'Used to simplify filtering of features', '#');
`,
cb,
);
};
exports.down = function(db, cb) {
db.runSql(
`DROP TABLE feature_tag;
DROP TABLE tags;
DROP TABLE tag_types;
`,
cb,
);
};