mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-25 08:25:09 +00:00
fix: handle missing super user scenario
Signed-off-by: mertmit <mertmit99@gmail.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const up = async (knex: Knex) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find super user
|
// find super user
|
||||||
const superUser = await knex(MetaTable.USERS)
|
let superUser = await knex(MetaTable.USERS)
|
||||||
.where('roles', 'like', '%super%')
|
.where('roles', 'like', '%super%')
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
@@ -43,9 +43,24 @@ const up = async (knex: Knex) => {
|
|||||||
if (!userCount || +userCount.count === 0) {
|
if (!userCount || +userCount.count === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark first created user on instance as super user
|
||||||
|
const firstUser = await knex(MetaTable.USERS)
|
||||||
|
.orderBy('created_at', 'asc')
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!firstUser)
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'No super user found in the system, cannot create default workspace',
|
'No appropriate user found in the system, cannot create default workspace',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await knex(MetaTable.USERS)
|
||||||
|
.update({
|
||||||
|
roles: 'org-level-creator,super',
|
||||||
|
})
|
||||||
|
.where('id', firstUser.id);
|
||||||
|
|
||||||
|
superUser = firstUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultWorkspaceId = `w${nanoidWorkspace()}`;
|
const defaultWorkspaceId = `w${nanoidWorkspace()}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user