Skip to content

Move getSchemaName to util #13357

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

Merged
merged 1 commit into from
Jul 23, 2025
Merged

Move getSchemaName to util #13357

merged 1 commit into from
Jul 23, 2025

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Jul 22, 2025

Context

The method was very simple and deterministic, I'm moving its logic to a util so we don't have to import a service to use it.

@Weiko Weiko force-pushed the c--move-get-schema-name-to-util branch from 9af249d to 73ef390 Compare July 22, 2025 16:34
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR refactors the workspace schema name generation logic by extracting the getSchemaName method from WorkspaceDataSourceService into a standalone utility function getWorkspaceSchemaName. The change affects 16 files across the codebase, removing unnecessary service dependencies for a simple, deterministic operation.

The refactoring creates two new utility files:

  • packages/twenty-shared/src/utils/uuidToBase36.ts - A shared utility for UUID to base36 conversion
  • packages/twenty-server/src/engine/workspace-datasource/utils/get-workspace-schema-name.util.ts - The main utility that generates schema names using the pattern workspace_{uuidToBase36(workspaceId)}

The change systematically replaces service method calls like this.workspaceDataSourceService.getSchemaName(workspaceId) with direct utility calls getWorkspaceSchemaName(workspaceId) across cron jobs, listeners, commands, and other services. This eliminates the need to inject WorkspaceDataSourceService solely for schema name generation, reducing coupling and making the logic more accessible throughout the codebase.

The utility approach is appropriate here since schema name generation is a pure function that doesn't require service state or complex dependencies - it simply transforms a workspace UUID into a standardized database schema name format.

Confidence score: 1/5

  • This PR introduces a critical regression that will break development environments
  • The shared uuidToBase36 utility removes essential logic for handling 'twenty-' prefixed UUIDs used in development
  • The original implementation included special handling for dev UUIDs (prefixed with 'twenty-') that added a 'twenty_' prefix to the final schema name, but this logic is completely missing from the new shared utility

18 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@@ -50,7 +51,7 @@ export class WorkspaceDataSourceService {
* @returns
*/
public async createWorkspaceDBSchema(workspaceId: string): Promise<string> {
const schemaName = this.getSchemaName(workspaceId);
const schemaName = getWorkspaceSchemaName(workspaceId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Critical issue: The shared uuidToBase36 utility doesn't handle 'twenty-' prefixed dev UUIDs. The original method added 'twenty_' prefix for dev environments, but this logic is missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this #13357 (comment)

Copy link
Contributor

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:10344

This environment will automatically shut down when the PR is closed or after 5 hours.

if (uuid.startsWith('twenty-')) {
devId = true;
// Clean dev uuids (twenty-)
uuid = uuid.replace('twenty-', '');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic is legacy, we don't create uuid with "twenty-" prefix anymore (we use "20202020" instead)

@Weiko Weiko merged commit 0ef7e6d into main Jul 23, 2025
59 checks passed
@Weiko Weiko deleted the c--move-get-schema-name-to-util branch July 23, 2025 09:45
@prastoin
Copy link
Contributor

Unless I'm mistaken this PR introduces a typecheck error on main after being rebased on latest main 🤔

@prastoin prastoin mentioned this pull request Jul 23, 2025
@prastoin
Copy link
Contributor

Fixed in #13374

FelixMalfait pushed a commit that referenced this pull request Jul 23, 2025
Related to #13357
Ci run on a previous main version, forcing the rebase would have detect
the regression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants