refactor: Setup typescript project references across workflow, core, and cli (#4519)

* refactor: use consistent folder structure across workflow, core, and cli

* setup typescript project references across workflow, core, and cli
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2022-11-09 15:25:00 +01:00
committed by GitHub
parent de96def372
commit 698d96a617
251 changed files with 1284 additions and 1134 deletions

View File

@@ -0,0 +1,66 @@
import { Not } from 'typeorm';
import * as Db from '@/Db';
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
import { BaseCommand } from '../BaseCommand';
export class Reset extends BaseCommand {
static description = '\nResets the database to the default user state';
async run(): Promise<void> {
const owner = await this.getInstanceOwner();
const ownerWorkflowRole = await Db.collections.Role.findOneOrFail({
name: 'owner',
scope: 'workflow',
});
const ownerCredentialRole = await Db.collections.Role.findOneOrFail({
name: 'owner',
scope: 'credential',
});
await Db.collections.SharedWorkflow.update(
{ user: { id: Not(owner.id) }, role: ownerWorkflowRole },
{ user: owner },
);
await Db.collections.SharedCredentials.update(
{ user: { id: Not(owner.id) }, role: ownerCredentialRole },
{ user: owner },
);
await Db.collections.User.delete({ id: Not(owner.id) });
await Db.collections.User.save(Object.assign(owner, this.defaultUserProps));
const danglingCredentials: CredentialsEntity[] =
(await Db.collections.Credentials.createQueryBuilder('credentials')
.leftJoinAndSelect('credentials.shared', 'shared')
.where('shared.credentialsId is null')
.getMany()) as CredentialsEntity[];
const newSharedCredentials = danglingCredentials.map((credentials) =>
Db.collections.SharedCredentials.create({
credentials,
user: owner,
role: ownerCredentialRole,
}),
);
await Db.collections.SharedCredentials.save(newSharedCredentials);
await Db.collections.Settings.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: 'false' },
);
await Db.collections.Settings.update(
{ key: 'userManagement.skipInstanceOwnerSetup' },
{ value: 'false' },
);
this.logger.info('Successfully reset the database to default user state.');
}
async catch(error: Error): Promise<void> {
this.logger.error('Error resetting database. See log messages for details.');
this.logger.error(error.message);
this.exit(1);
}
}