fix: handle missing super user scenario

Signed-off-by: mertmit <mertmit99@gmail.com>
This commit is contained in:
mertmit
2026-01-23 15:25:31 +03:00
parent 84f921efb9
commit b755ef15c1

View File

@@ -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()}`;