Skip to content
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

chore(rethinkdb): TemplateScale: One-shot #10021

Merged
merged 32 commits into from
Jul 25, 2024
Merged

Conversation

mattkrick
Copy link
Member

@mattkrick mattkrick commented Jul 23, 2024

Description

moves TemplateScale to PG in one shot (it's such a small, rarely used table that 1 shot is OK)

Summary by CodeRabbit

  • New Features

    • Introduced a new sorting mechanism in the Select Scale Dropdown to prioritise starter scales.
    • Added GraphQL resolvers for TemplateScale, TemplateScaleRef, and TemplateScaleValue to enhance data handling in queries.
  • Bug Fixes

    • Improved error handling in mutations for better user feedback.
    • Updated logic to ensure template scales are only retrieved if they exist, reducing potential runtime errors.
  • Improvements

    • Transitioned database operations from RethinkDB to PostgreSQL for better performance and maintainability.
    • Enhanced type safety across various modules by refining type definitions and query methods.
    • Simplified logic for fetching scales in GraphQL queries to improve performance.
    • Added a custom sort order management utility to streamline real-time editing of ordered sequences.

mattkrick added 21 commits July 15, 2024 15:16
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Signed-off-by: Matt Krick <[email protected]>
Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

@mattkrick mattkrick changed the base branch from master to chore/teamMember-phase3 July 23, 2024 23:39
@github-actions github-actions bot added size/l and removed size/xl labels Jul 23, 2024
Base automatically changed from chore/teamMember-phase3 to master July 24, 2024 19:06
@github-actions github-actions bot added size/xl and removed size/l labels Jul 24, 2024
Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

Signed-off-by: Matt Krick <[email protected]>
@mattkrick mattkrick marked this pull request as ready for review July 24, 2024 21:32
Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

@github-actions github-actions bot requested a review from tianrunhe July 24, 2024 21:33
Copy link
Contributor

coderabbitai bot commented Jul 24, 2024

Walkthrough

The recent changes focus on enhancing data handling and integration mechanisms within a PostgreSQL context, transitioning from RethinkDB. Key modifications include the introduction of new data loaders, refined GraphQL resolvers for template scales, improved sorting and retrieval functionalities, and a shift towards implicit typing in TypeScript. These updates streamline various components, optimise performance, and enhance code clarity, ensuring a more robust and efficient application architecture.

Changes

Files Change Summary
codegen.json Added new type mappings: TemplateScaleValue, TemplateScale, and TemplateScaleRef.
packages/client/modules/meeting/components/SelectScaleDropdown.tsx Enhanced scale sorting logic to prioritise isStarter properties and improved rendering logic.
packages/client/mutations/AddPokerTemplateScaleMutation.ts Updated GraphQL fragment to include additional fields from ScaleDropdownMenuItem_scale.
packages/client/mutations/RemovePokerTemplateScaleMutation.ts Adjusted indentation of the dimensions field in the mutation query for clarity.
packages/client/mutations/handlers/handleAddPokerTemplateScale.ts Simplified logic to directly manipulate linked records instead of using an external utility function.
packages/client/utils/dndNoise.ts Added deprecation notice for dndNoise function, recommending use of sortOrder.ts.
packages/embedder/indexing/meetingTemplate.ts Changed method to load template scales to ensure non-null retrieval.
packages/server/database/rethinkDriver.ts Removed MeetingTemplate and TemplateScale types from the schema, simplifying the structure.
packages/server/dataloader/customRedisQueries.ts Removed starterScales method, impacting scale retrieval capabilities.
packages/server/dataloader/foreignKeyLoaderMakers.ts Introduced scalesByTeamId loader for fetching template scales by team IDs.
packages/server/dataloader/primaryKeyLoaderMakers.ts Added templateScales loader for fetching template scales by specified IDs.
packages/server/graphql/mutations/addPokerTemplateDimension.ts Streamlined scale retrieval using data loader and in-memory sorting.
packages/server/graphql/mutations/addPokerTemplateScale.ts Shifted operations from RethinkDB to PostgreSQL, refactoring logic for efficiency.
packages/server/graphql/mutations/addPokerTemplateScaleValue.ts Improved error handling and streamlined the insertion of scale values.
packages/server/graphql/mutations/helpers/validateScaleValue.ts Removed validateScaleLabelValueUniqueness function, altering validation logic.
packages/server/graphql/mutations/movePokerTemplateScaleValue.ts Optimised the update logic for moving scale values, enhancing performance.
packages/server/graphql/mutations/removePokerTemplateScale.ts Transitioned to Kysely for updates in TemplateScale, introducing conditional checks.
packages/server/graphql/mutations/removePokerTemplateScaleValue.ts Updated logic to use data loader for scale retrieval; simplified deletion operations.
packages/server/graphql/mutations/renamePokerTemplateScale.ts Modernised database interactions, improving scale retrieval and update logic.
packages/server/graphql/public/types/TemplateScale.ts Introduced a resolver for template scales, implementing active checks and data processing functions.
packages/server/graphql/public/types/TemplateScaleRef.ts Defined a resolver for TemplateScaleRef with enhanced output structure.
packages/server/graphql/public/types/TemplateScaleValue.ts Established the TemplateScaleValue type and resolver, generating unique identifiers for scale values.
packages/server/graphql/types/Team.ts Simplified the scales field resolution logic, optimising data fetching.
packages/server/graphql/types/TemplateScale.ts Removed all fields from TemplateScale, rendering it a placeholder.
packages/server/graphql/types/TemplateScaleRef.ts Simplified TemplateScaleRef by removing all previously defined fields.
packages/server/postgres/migrations/1614030642692_refs-for-meetings.ts Broadened the type for scale property and uniqueScales in migration, reducing type safety.
packages/server/postgres/migrations/1721405703862_TemplateScale.ts Implemented migration logic for managing TemplateScale and TemplateScaleValue tables in PostgreSQL.
packages/server/postgres/select.ts Introduced selectTemplateScale function for querying template scales with associated values.
packages/server/postgres/types/index.d.ts Defined new types for TemplateScale and TemplateScaleRef, enhancing type safety.
packages/server/utils/analytics/analytics.ts Restricted parameter type for scale in scaleMetrics for better type safety.
packages/server/utils/sortOrder.ts Introduced functions for managing a custom sort order, allowing for real-time adjustments.
packages/server/postgres/migrations/1698265600000_addPrioritizationTemplates.ts Removed import of TemplateScale and shifted to implicit typing for MOSCOW_SCALE_CONFIG.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphQL
    participant DataLoader
    participant PostgreSQL

    Client->>GraphQL: Query for TemplateScale
    GraphQL->>DataLoader: Load TemplateScale data
    DataLoader->>PostgreSQL: Query TemplateScale
    PostgreSQL-->>DataLoader: Return TemplateScale data
    DataLoader-->>GraphQL: Provide loaded data
    GraphQL-->>Client: Respond with TemplateScale data
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 14c1a73 and ba174ac.

Files selected for processing (1)
  • packages/server/postgres/migrations/1698265600000_addPrioritizationTemplates.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/server/postgres/migrations/1698265600000_addPrioritizationTemplates.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (2)
packages/server/graphql/public/types/TemplateScale.ts (1)

11-20: Resolver dimensions looks good but consider error handling.

The resolver correctly fetches dimensions from RethinkDB, but it lacks error handling.

Consider adding error handling to manage potential issues with the database query.

+ try {
+   const r = await getRethink()
+   return r
+     .table('TemplateDimension')
+     .getAll(teamId, {index: 'teamId'})
+     .filter((row: RDatum) =>
+       row('removedAt').default(null).eq(null).and(row('scaleId').eq(scaleId))
+     )
+     .run()
+ } catch (error) {
+   console.error('Error fetching dimensions:', error)
+   throw new Error('Failed to fetch dimensions')
+ }
packages/server/database/rethinkDriver.ts (1)

Verify the impact of removing TemplateScale.

The removal of the TemplateScale type from the RethinkSchema affects multiple parts of the codebase. The following files contain references to TemplateScale and need to be updated or have the references removed accordingly:

  • packages/server/utils/analytics/analytics.ts
  • packages/server/postgres/select.ts
  • packages/server/postgres/types/index.d.ts
  • packages/server/postgres/migrations/1721405703862_TemplateScale.ts
  • packages/server/postgres/migrations/1614030642692_refs-for-meetings.ts
  • packages/server/postgres/queries/getTemplateScaleRefsByIds.ts
  • packages/server/postgres/migrations/1698265600000_addPrioritizationTemplates.ts
  • packages/server/postgres/migrations/1613005669863_template-refs.ts
  • packages/server/postgres/generatedMigrationHelpers.ts
  • packages/server/graphql/types/AddTemplateScaleInput.ts
  • packages/server/graphql/types/TemplateScaleRef.ts
  • packages/server/graphql/types/TemplateScale.ts
  • packages/server/graphql/types/Team.ts
  • packages/server/graphql/types/UpdatePokerTemplateScaleValuePayload.ts
  • packages/server/graphql/types/TemplateScaleInput.ts
  • packages/server/graphql/types/TemplateDimensionRef.ts
  • packages/server/graphql/types/TemplateDimension.ts
  • packages/server/graphql/types/RenamePokerTemplateScalePayload.ts
  • packages/server/graphql/types/RemovePokerTemplateScaleValuePayload.ts
  • packages/server/graphql/types/RemovePokerTemplateScalePayload.ts
  • packages/server/graphql/types/MovePokerTemplateScaleValuePayload.ts
  • packages/server/graphql/types/AddPokerTemplateScaleValuePayload.ts
  • packages/server/graphql/types/AddPokerTemplateScalePayload.ts
  • packages/server/graphql/rootMutation.ts
  • packages/server/graphql/public/types/TemplateScaleValue.ts
  • packages/server/graphql/public/types/TemplateScaleRef.ts
  • packages/server/graphql/public/types/TemplateScale.ts
  • packages/server/graphql/mutations/updatePokerTemplateScaleValue.ts
  • packages/server/graphql/mutations/startSprintPoker.ts
  • packages/server/graphql/mutations/removePokerTemplateScaleValue.ts
  • packages/server/graphql/mutations/renamePokerTemplateScale.ts
  • packages/server/graphql/mutations/removePokerTemplateScale.ts
  • packages/server/graphql/mutations/addPokerTemplateScaleValue.ts
  • packages/server/graphql/mutations/addPokerTemplateScale.ts
  • packages/server/dataloader/primaryKeyLoaderMakers.ts
  • packages/server/dataloader/foreignKeyLoaderMakers.ts
  • packages/server/database/migrations/20201214104322-noPokerSpecial.ts
  • packages/server/database/migrations/20210330163028-addPriorityScale.ts
  • packages/server/database/types/EstimateUserScore.ts
  • packages/server/database/migrations/20201118132835-removeValueFieldInScaleValue.ts
  • packages/server/database/migrations/20201014110000-templateScale.ts
  • packages/server/database/migrations/20200824105351-pokerTemplate.ts
  • packages/server/database/migrations/20200803123551-addTemplateScale.ts
  • packages/client/subscriptions/TeamSubscription.ts
  • packages/client/mutations/RenamePokerTemplateScaleMutation.ts
  • packages/client/mutations/RemovePokerTemplateScaleMutation.ts
  • packages/client/mutations/AddPokerTemplateScaleMutation.ts
  • packages/client/mutations/UpdatePokerTemplateScaleValueMutation.ts
  • packages/client/mutations/UpdatePokerScopeMutation.ts
  • packages/client/mutations/RemovePokerTemplateScaleValueMutation.ts
  • packages/client/mutations/MovePokerTemplateScaleValueMutation.ts
  • packages/client/modules/meeting/components/PokerTemplateScalePicker.tsx
  • packages/client/modules/meeting/components/ScaleActions.tsx
  • packages/client/modules/meeting/components/SelectScaleDropdown.tsx
  • packages/client/modules/meeting/components/TemplateScaleValueList.tsx
  • packages/client/modules/meeting/components/EditableTemplateScaleValueLabel.tsx
  • packages/client/modules/meeting/components/TemplateScaleValueItem.tsx
  • packages/client/modules/meeting/components/EditableTemplateScaleName.tsx
  • packages/client/modules/meeting/components/EditableTemplateScaleValueColor.tsx
  • packages/client/modules/meeting/components/AddPokerTemplateScaleValue.tsx
  • packages/client/modules/meeting/components/AddScaleValueButtonInput.tsx
  • packages/client/modules/meeting/components/TemplateDimensionItem.tsx
  • packages/client/modules/meeting/components/ScaleValuePalettePicker.tsx
  • packages/client/modules/meeting/components/ScaleDropdownMenuItem.tsx
  • packages/client/modules/meeting/components/PokerTemplateScaleDetails.tsx
  • packages/client/hooks/usePortal.tsx
  • packages/client/modules/meeting/components/NewTemplateScaleValueLabelInput.tsx
  • packages/client/components/PokerVotingRow.tsx
  • packages/client/components/PokerCard.tsx
  • packages/client/components/ActivityLibrary/ActivityDetails/TemplateDetails.tsx

Please ensure that all references to TemplateScale are updated or removed accordingly.

Analysis chain

Line range hint 64-64:
Verify the impact of removing TemplateScale.

The removal of the TemplateScale type from the RethinkSchema might affect components or services relying on this type. Ensure that all references to TemplateScale are updated or removed accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing `TemplateScale`.

# Test: Search for references to `TemplateScale`. Expect: No references to `TemplateScale`.
rg --type python -A 5 $'TemplateScale'

Length of output: 68


Script:

#!/bin/bash
# Description: Verify the impact of removing `TemplateScale`.

# Test: Search for references to `TemplateScale`. Expect: No references to `TemplateScale`.
rg --type ts -A 5 $'TemplateScale'

Length of output: 170626

}[]

const uniqueScaleIdSet = new Set<string>()
const uniqueScales = [] as TemplateScale[]
const uniqueScales = [] as any[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential issue with changing the type of uniqueScales to any.

Changing the type of uniqueScales from TemplateScale to any sacrifices type safety and may lead to unexpected behaviour. Consider maintaining type safety by using a more specific type.

-    const uniqueScales = [] as any[]
+    const uniqueScales = [] as TemplateScale[]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const uniqueScales = [] as any[]
const uniqueScales = [] as TemplateScale[]

@@ -58,11 +57,11 @@
.run()) as {
id: string
name: string
dimensions: (TemplateDimension & {scale: TemplateScale})[]
dimensions: (TemplateDimension & {scale: any})[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential issue with changing the type to any.

Changing the type of the scale property from TemplateScale to any sacrifices type safety and may lead to unexpected behaviour. Consider maintaining type safety by using a more specific type.

-    dimensions: (TemplateDimension & {scale: any})[]
+    dimensions: (TemplateDimension & {scale: TemplateScale})[]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dimensions: (TemplateDimension & {scale: any})[]
dimensions: (TemplateDimension & {scale: TemplateScale})[]

Signed-off-by: Matt Krick <[email protected]>
Copy link
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR will be delayed and might be rejected due to its size.

@tianrunhe tianrunhe removed their request for review July 24, 2024 22:31
@mattkrick mattkrick merged commit 0c6c8e7 into master Jul 25, 2024
8 checks passed
@mattkrick mattkrick deleted the chore/templateScale branch July 25, 2024 00:10
@github-actions github-actions bot mentioned this pull request Jul 25, 2024
24 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant