-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: twenty orm for standard and custom objects #6178
Conversation
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.
PR Summary
- Dynamic Schema Generation: Refactored
EntitySchemaColumnFactory
,EntitySchemaRelationFactory
, andEntitySchemaFactory
to support dynamic schema generation from database metadata. - Custom Object Repository: Updated
TwentyORMManager
to retrieve repositories for custom objects using metadata names. - Storage Management: Introduced
ObjectEntitiesStorage
for managing entity schemas and metadata, removedObjectLiteralStorage
. - Dependency Updates: Added
lodash.lowerfirst
topackage.json
for handling object names. - Scoped Workspace Handling: Renamed and simplified
ScopedWorkspaceDatasourceFactory
toScopedWorkspaceIdFactory
.
12 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
packages/twenty-server/src/engine/twenty-orm/factories/entity-schema.factory.ts
Show resolved
Hide resolved
8785138
to
d9d8480
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.
PR Summary
(updates since last review)
- Updated
workspace.repository.ts
to useObjectEntitiesStorage.getObjectMetadataEntity
for dynamic schema generation. - Renamed methods in
object-entities.storage.ts
for clarity. - Added methods in
object-entities.storage.ts
to retrieve collections and entities by metadata name.
No major changes found since last review.
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Updated
packages/twenty-server/src/engine/twenty-orm/factories/entity-schema.factory.ts
to support dynamic schema generation from metadata. - Added
getObjectMetadataByName
method inentity-schema.factory.ts
for fetching metadata. - Modified
packages/twenty-server/src/engine/twenty-orm/repository/workspace.repository.ts
to useObjectEntitiesStorage.getObjectMetadataEntity
. - Renamed methods in
packages/twenty-server/src/engine/twenty-orm/storage/object-entities.storage.ts
for clarity. - Enhanced
object-entities.storage.ts
with new methods for retrieving metadata and entity schemas.
3 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
if (!objectMetadata) { | ||
throw new Error('Object metadata not found'); |
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.
🧠 logic: Throws an error if objectMetadata
is not found.
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.
PR Summary
(updates since last review)
- Modified
packages/twenty-server/src/database/typeorm/typeorm.module.ts
to support dynamic schema generation. - Introduced
cacheVersion
parameter inpackages/twenty-server/src/engine/twenty-orm/factories/workspace-datasource.factory.ts
. - Renamed
ScopedWorkspaceIdFactory
toScopedWorkspaceContextFactory
inpackages/twenty-server/src/engine/twenty-orm/factories/index.ts
. - Added logic to destroy outdated data sources in
packages/twenty-server/src/engine/twenty-orm/storage/data-source.storage.ts
. - Updated
packages/twenty-server/src/engine/twenty-orm/twenty-orm.manager.ts
for dynamic schema generation and cache version management.
10 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
@@ -7,6 +7,16 @@ export class DataSourceStorage { | |||
new Map(); | |||
|
|||
public static getDataSource(key: string): WorkspaceDataSource | undefined { | |||
// Destroy all data sources that belong to the workspace if the cache version change | |||
for (const [dataSourceKey, dataSource] of this.dataSources.entries()) { | |||
const workspaceId = key.split('-')?.[0]; |
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.
🪶 style: Consider adding a null check for key.split('-')
to avoid potential runtime errors.
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.
PR Summary
(updates since last review)
- Added
UpgradeTo0_22CommandModule
inpackages/twenty-server/src/database/commands/database-command.module.ts
- Removed
UpdateBooleanFieldsNullDefaultValuesAndNullValuesCommand
inpackages/twenty-server/src/database/commands/database-command.module.ts
- Introduced
FixObjectMetadataIdStandardIdCommand
inpackages/twenty-server/src/database/commands/upgrade-version/0-22/0-22-fix-object-metadata-id-standard-id.command.ts
- Renamed and updated command in
packages/twenty-server/src/database/commands/upgrade-version/0-22/0-22-update-boolean-fields-null-default-values-and-null-values.command.ts
- Added
UpgradeTo0_22Command
and module inpackages/twenty-server/src/database/commands/upgrade-version/0-22/0-22-upgrade-version.command.ts
and0-22-upgrade-version.module.ts
5 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Added Kubernetes and Terraform configurations for deploying TwentyCRM (
packages/twenty-docker/k8s/
). - Enhanced link handling logic in
LinksFieldInput.tsx
andLinksFieldMenuItem.tsx
(packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/
). - Renamed 'emailAliases' to 'handleAliases' across multiple files for consistency (
packages/twenty-server/src/modules/connected-account/
,packages/twenty-server/src/modules/messaging/
). - Modified validation schema to allow empty strings as valid URLs (
packages/twenty-front/src/utils/validation-schemas/absoluteUrlSchema.ts
). - Updated dropdown rendering logic to use portals for better positioning (
packages/twenty-front/src/modules/ui/layout/dropdown/components/Dropdown.tsx
).
45 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Switched from
InjectWorkspaceRepository
toTwentyORMManager
for repository management (packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts
) - Updated methods to retrieve repositories dynamically (
packages/twenty-server/src/engine/core-modules/calendar/timeline-calendar-event.service.ts
) - Introduced dynamic schema generation from database metadata (
packages/twenty-server/src/engine/twenty-orm/twenty-orm.manager.ts
) - Added custom object repository retrieval (
packages/twenty-server/src/engine/twenty-orm/twenty-orm.manager.ts
) - New method
getRepositoryForWorkspace
for specific workspace repositories (packages/twenty-server/src/engine/twenty-orm/twenty-orm.manager.ts
)
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
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.
PR Summary
(updates since last review)
- Replaced direct repository injections with dynamic retrieval using
TwentyORMManager
(packages/twenty-server/src/engine/core-modules/auth/services/google-apis.service.ts
) - Updated repository retrieval to use
TwentyORMManager
for dynamic schema generation (packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job.ts
) - Refactored services to dynamically obtain repositories via
TwentyORMManager
(packages/twenty-server/src/modules/calendar/calendar-event-cleaner/services/calendar-event-cleaner.service.ts
) - Enhanced flexibility by dynamically fetching repositories in various services (
packages/twenty-server/src/modules/calendar/calendar-event-import-manager/services/calendar-events-import.service.ts
) - Aligned repository management with new ORM capabilities for custom objects (
packages/twenty-server/src/modules/messaging/message-cleaner/services/messaging-message-cleaner.service.ts
)
18 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
This reverts commit 4a496ab.
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.
PR Summary
(updates since last review)
- Replaced
WorkspaceSchemaStorageModule
withWorkspaceCacheStorageModule
for dynamic schema generation (packages/twenty-server/src/engine/api/graphql/core-graphql-api.module.ts
) - Updated
WorkspaceSchemaStorageService
toWorkspaceCacheStorageService
for dynamic schema generation (packages/twenty-server/src/engine/api/graphql/workspace-schema.factory.ts
) - Introduced
CacheManager
class for caching dynamic schemas (packages/twenty-server/src/engine/twenty-orm/storage/cache-manager.storage.ts
) - Refactored repository injections to use
InjectWorkspaceRepository
instead ofTwentyORMManager
(packages/twenty-server/src/modules/calendar/blocklist-manager/jobs/blocklist-item-delete-calendar-events.job.ts
) - Added
TestModule
andTestResolver
to demonstrate dynamic schema generation (packages/twenty-server/src/engine/core-modules/test-module/test.module.ts
,packages/twenty-server/src/engine/core-modules/test-module/test.resolver.ts
)
34 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings
packages/twenty-server/src/engine/core-modules/test-module/test.resolver.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/storage/cache-manager.storage.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/storage/cache-manager.storage.ts
Outdated
Show resolved
Hide resolved
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.
PR Summary
(updates since last review)
- Added
internalContext
initialization increateEntityManager
method (packages/twenty-server/src/engine/twenty-orm/datasource/workspace.datasource.ts
) - Introduced
internalContext
inWorkspaceEntityManager
constructor and updatedgetRepository
method (packages/twenty-server/src/engine/twenty-orm/entity-manager/entity.manager.ts
) - Added
workspaceId
parameter tocreate
method for dynamic schema generation (packages/twenty-server/src/engine/twenty-orm/factories/entity-schema-column.factory.ts
) - Removed
getRelationType
method and centralized relation details logic (packages/twenty-server/src/engine/twenty-orm/factories/entity-schema-relation.factory.ts
) - Deleted
data-source.storage.ts
file, indicating a refactor in data source management (packages/twenty-server/src/engine/twenty-orm/storage/data-source.storage.ts
)
18 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings
packages/twenty-server/src/engine/twenty-orm/datasource/workspace.datasource.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/entity-manager/entity.manager.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/factories/entity-schema.factory.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/storage/cache-manager.storage.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/utils/determine-relation-details.util.ts
Outdated
Show resolved
Hide resolved
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.
PR Summary
(updates since last review)
- Removed
TestModule
and related files (packages/twenty-server/src/engine/core-modules/core-engine.module.ts
,packages/twenty-server/src/engine/core-modules/test-module/test.module.ts
,packages/twenty-server/src/engine/core-modules/test-module/test.resolver.ts
) - Improved
WorkspaceEntityManager
initialization and dynamic schema generation (packages/twenty-server/src/engine/twenty-orm/datasource/workspace.datasource.ts
) - Cleaned up logging in
WorkspaceEntityManager
(packages/twenty-server/src/engine/twenty-orm/entity-manager/entity.manager.ts
) - Enhanced dynamic schema generation using
WorkspaceEntitiesStorage
(packages/twenty-server/src/engine/twenty-orm/factories/entity-schema.factory.ts
) - Introduced dynamic schema generation and repository retrieval for custom objects (
packages/twenty-server/src/engine/twenty-orm/repository/workspace.repository.ts
,packages/twenty-server/src/engine/twenty-orm/twenty-orm.manager.ts
)
10 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings
if (!objectMetadata) { | ||
throw new Error('Object metadata not found'); |
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.
Logic: Throws an error if objectMetadata
is not found.
): Promise<WorkspaceRepository<T>>; | ||
|
||
async getRepository<T extends ObjectLiteral>( | ||
entityClassOrobjectMetadataName: Type<T> | string, |
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.
Style: Consider renaming entityClassOrobjectMetadataName
to entityClassOrObjectMetadataName
for better readability.
Overview
This PR builds upon #5153, adding the ability to get a repository for custom objects. The
entitySchema
is now generated for both standard and custom objects based on metadata stored in the database instead of the decoratedWorkspaceEntity
in the code. This change ensures that standard objects with custom fields and relations can also support custom objects.Implementation Details
Key Changes:
Dynamic Schema Generation: The
entitySchema
for standard and custom objects is now dynamically generated from the metadata stored in the database. This shift allows for greater flexibility and adaptability, particularly for standard objects with custom fields and relations.Custom Object Repository Retrieval: A repository for a custom object can be retrieved using
TwentyORMManager
based on the object's name. Here's an example of how this can be achieved:Fix #6179