-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Move getSchemaName to util #13357
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../src/engine/metadata-modules/remote-server/remote-table/utils/fetch-table-columns.util.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ges/twenty-server/src/engine/workspace-datasource/utils/get-workspace-schema-name.util.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { uuidToBase36 } from 'twenty-shared/utils'; | ||
|
||
export const getWorkspaceSchemaName = (workspaceId: string): string => { | ||
return `workspace_${uuidToBase36(workspaceId)}`; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
PermissionsException, | ||
PermissionsExceptionCode, | ||
} from 'src/engine/metadata-modules/permissions/permissions.exception'; | ||
import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util'; | ||
|
||
@Injectable() | ||
export class WorkspaceDataSourceService { | ||
|
@@ -50,7 +51,7 @@ export class WorkspaceDataSourceService { | |
* @returns | ||
*/ | ||
public async createWorkspaceDBSchema(workspaceId: string): Promise<string> { | ||
const schemaName = this.getSchemaName(workspaceId); | ||
const schemaName = getWorkspaceSchemaName(workspaceId); | ||
|
||
return await this.typeormService.createSchema(schemaName); | ||
} | ||
|
@@ -63,45 +64,11 @@ export class WorkspaceDataSourceService { | |
* @returns | ||
*/ | ||
public async deleteWorkspaceDBSchema(workspaceId: string): Promise<void> { | ||
const schemaName = this.getSchemaName(workspaceId); | ||
const schemaName = getWorkspaceSchemaName(workspaceId); | ||
|
||
return await this.typeormService.deleteSchema(schemaName); | ||
} | ||
|
||
/** | ||
* | ||
* Get the schema name for a workspace | ||
* Note: This is assuming that the workspace only has one schema but we should prefer querying the metadata table instead. | ||
* | ||
* @param workspaceId | ||
* @returns string | ||
*/ | ||
public getSchemaName(workspaceId: string): string { | ||
return `workspace_${this.uuidToBase36(workspaceId)}`; | ||
} | ||
|
||
/** | ||
* | ||
* Convert a uuid to base36 | ||
* | ||
* @param uuid | ||
* @returns string | ||
*/ | ||
private uuidToBase36(uuid: string): string { | ||
let devId = false; | ||
|
||
if (uuid.startsWith('twenty-')) { | ||
devId = true; | ||
// Clean dev uuids (twenty-) | ||
uuid = uuid.replace('twenty-', ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
} | ||
const hexString = uuid.replace(/-/g, ''); | ||
const base10Number = BigInt('0x' + hexString); | ||
const base36String = base10Number.toString(36); | ||
|
||
return `${devId ? 'twenty_' : ''}${base36String}`; | ||
} | ||
|
||
public async executeRawQuery( | ||
_query: string, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
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.
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.
See this #13357 (comment)