1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/src/migrations/20220603081324-add-archive-at-to-feature-toggle.js
sellinjaanus 04fb065df4
Added missing archivedAt to featureSchema (#1779)
* Added missing archivedAt to featureSchema

* Added archivedAt to feature toggle.
Added archived_at to db

* Add test

* Add test

* Bug fix

* Bug fix

* update archivedAt to date-time

* Code refactoring done

* Conver to static and remove unused methods

* Add tests

* Fixes

* Fix

* Removed docker file from linting

* Fix segment test

* Fix failing test

* Make fixes

Co-authored-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: andreas-unleash <104830839+andreas-unleash@users.noreply.github.com>
2022-07-01 11:51:26 +00:00

39 lines
1.1 KiB
JavaScript

'use strict';
exports.up = function (db, callback) {
db.runSql(
`
ALTER TABLE features ADD archived_at TIMESTAMP WITH TIME ZONE;
UPDATE features f
SET archived_at = res.archived_at
FROM (SELECT f.name, e.created_at AS archived_at
FROM features f
INNER JOIN events e
ON e.feature_name = f.NAME
AND e.created_at =
(SELECT Max(created_at) date
FROM events
WHERE type = 'feature-archived'
AND e.feature_name = f.NAME)) res
WHERE res.NAME = f.NAME;
UPDATE features
SET archived_at = Now()
WHERE archived = TRUE
AND archived_at IS NULL;
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
UPDATE features
SET archived = TRUE
WHERE archived_at IS NOT NULL;
ALTER TABLE features DROP COLUMN archived_at;
`,
callback,
);
};