Skip to content

Commit

Permalink
feat: add created_by and status columns to change_request_schedule (#…
Browse files Browse the repository at this point in the history
…5203)

Adds 2 columns to change_request_schedule

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
  • Loading branch information
andreas-unleash committed Oct 30, 2023
1 parent 54cb9b6 commit 6875daf
Showing 1 changed file with 26 additions and 0 deletions.
@@ -0,0 +1,26 @@
'use strict';

exports.up = function (db, cb) {
db.runSql(`
CREATE TYPE change_request_schedule_status AS ENUM ('pending', 'failed');
ALTER TABLE change_request_schedule
ADD COLUMN IF NOT EXISTS created_by integer REFERENCES users(id);
ALTER TABLE change_request_schedule
ADD COLUMN IF NOT EXISTS status change_request_schedule_status default 'pending';
`, cb);
};

exports.down = function (db, cb) {
db.runSql(`
ALTER TABLE change_request_schedule
DROP COLUMN IF EXISTS created_by;
ALTER TABLE change_request_schedule
DROP COLUMN IF EXISTS status;
DROP TYPE change_request_schedule_status
`, cb);
};

1 comment on commit 6875daf

@ivarconr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of putting custom types change_request_schedule_status in to the database?

I would rather like to keep this logic in code, and have the database a bit more "dumb". Why?

  • By defining the domain logic in to the database itself we put us in hard situations. E.g. if we want new legal enum values we would need to migrate the db first, and than in a separate commit change our usage.
  • If we later need to introduce new enum values and use them in code in the same changeset it can lead to Unleash crashing during rollout of the new version.

Please sign in to comment.