1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: migrate only users without any role

This commit is contained in:
Ivar Conradi Østhus 2021-04-28 12:56:19 +02:00
parent 6c57aeb232
commit 65fad95c6f
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09

View File

@ -2,8 +2,8 @@
const async = require('async'); const async = require('async');
function resolveRoleName(permissions = []) { function resolveRoleName(permissions) {
if (permissions.length === 0) { if (!permissions || permissions.length === 0) {
return 'Viewer'; return 'Viewer';
} }
if (permissions.includes('ADMIN')) { if (permissions.includes('ADMIN')) {
@ -13,7 +13,9 @@ function resolveRoleName(permissions = []) {
} }
exports.up = function(db, cb) { exports.up = function(db, cb) {
db.runSql(`SELECT id, permissions from users;`, (err, results) => { db.runSql(
`SELECT id, permissions from users WHERE id NOT IN (select user_id from role_user);`,
(err, results) => {
if (results.rowCount > 0) { if (results.rowCount > 0) {
const users = results.rows; const users = results.rows;
const insertRootRole = users.map(u => { const insertRootRole = users.map(u => {
@ -30,7 +32,8 @@ exports.up = function(db, cb) {
} else { } else {
cb(); cb();
} }
}); },
);
}; };
exports.down = function(db, cb) { exports.down = function(db, cb) {