From 013b0d60f2539eca9503e91bee82c395efe42220 Mon Sep 17 00:00:00 2001 From: David Leek Date: Tue, 12 Dec 2023 11:19:44 +0100 Subject: [PATCH] chore: add migration that adds is_system column and inserts system user --- .../20231212094343-unleash-system-user.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/migrations/20231212094343-unleash-system-user.js diff --git a/src/migrations/20231212094343-unleash-system-user.js b/src/migrations/20231212094343-unleash-system-user.js new file mode 100644 index 000000000000..a4d7c9586163 --- /dev/null +++ b/src/migrations/20231212094343-unleash-system-user.js @@ -0,0 +1,25 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + ALTER TABLE users ADD COLUMN IF NOT EXISTS is_system BOOLEAN NOT NULL DEFAULT FALSE; + DELETE FROM users WHERE id = -1337; + INSERT INTO users + (id, name, username, email, created_by, is_system) + VALUES + (-1337, 'Used by unleash internally for performing system actions that have no user', 'unleash_system_user', 'system@getunleash.io', -1337, true); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + ALTER TABLE users DROP COLUMN IF EXISTS is_system; + DELETE FROM users WHERE id = -1337; + `, + callback, + ); +};