-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: workspace health #3344
feat: workspace health #3344
Conversation
9bc6052
to
ad0fd72
Compare
465b8d2
to
8aa9d9d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's great! I feel like we will benefit a lot from unit tests for this part but does not have to be in this PR 🙂
message: `Table ${objectMetadata.targetTableName} not found in schema ${schemaName}`, | ||
}); | ||
|
||
return issues; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably unnecessary since we return issues
after this condition anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's here in case we add more check after this condition, if table doesn't exist we don't have to check anything else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright 👍
return 'now()'; | ||
default: | ||
throw new BadRequestException('Invalid dynamic default value type'); | ||
const serializedTypeDefaultValue = serializeTypeDefaultValue(defaultValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the naming a bit confusing because this function is already serialising default value based on their types.
I know why you did that though 😅. Maybe we should have named
{
type: something
}
to
{
strategy: something
}
Anyway, not a big issue, just wanted to mention it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree with that, manipulating it doesn't seems really nice with that name, but it's better to change this in another PR 🙂
packages/twenty-server/src/workspace/workspace-health/commands/workspace-health.command.ts
Outdated
Show resolved
Hide resolved
import { FieldMetadataEntity } from 'src/metadata/field-metadata/field-metadata.entity'; | ||
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity'; | ||
|
||
export enum WorkspaceHealthIssueType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I can already see us benefiting a lot from this for debugging 💪
packages/twenty-server/src/workspace/workspace-health/services/database-structure.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/workspace/workspace-health/services/database-structure.service.ts
Outdated
Show resolved
Hide resolved
defaultValue && 'value' in defaultValue ? defaultValue.value : null; | ||
|
||
if (typeof value === 'number') { | ||
return value.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because default values are stored as "strings" in DB for numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't really know if they are stored as string, but in my structure query they are strings
); | ||
|
||
if (!workspaceTableColumns) { | ||
throw new NotFoundException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Not for this PR but we should probably not return httpExceptions in this kind of code. Actually we should probably not throw httpExceptions in services at all. Since we don't have our own Error classes yet I think it's fine for now but just wanted to mention it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that, in Nest.JS documentation it's advised to use HttpException
for Rest or GraphQL API, we should I guess throw class errors in service and wrap them inside the controller or resolver, but it's going to be a lot verbose 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Yes I'm sure we can find a way to make this less verbose though, I find it weird to have HttpExceptions inside commands where http is not exposed. 🤔 Let's discuss this later 👍
packages/twenty-server/src/workspace/workspace-health/services/field-metadata-health.service.ts
Outdated
Show resolved
Hide resolved
} | ||
|
||
// Try to connect to the data source | ||
await this.typeORMService.connectToDataSource(dataSourceMetadata); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to connect to the workspace datasource here? This is to check if this settings are valid and that we can connect later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly, it's just to check if the connection to this workspace is working properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💪 !
Introducing the
workspace:health
CommandIn this PR, we're introducing a new command:
workspace:health
. This command is designed to assess the health of a specified workspace by examining its metadata and database structure.Key Features
How It Works
Run this command in your terminal as follows:
$ yarn command workspace:health --workspace-id 20202020-1c25-4d02-bf25-6aeccf7ea419
Customizable Parameters
Mode Selection (
-m, --mode [all | structure | metadata]
):all
: Checks both structure and metadata.structure
: Focuses on the database table structure based on metadata.metadata
: Concentrates on the validity of metadata.Verbose Output (
-v, --verbose
):Warning
Relations are not yet checked