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

fix: colors of the prompts for the threat level retro match now the prompts' names #9956

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

rafaelromcar-parabol
Copy link
Contributor

@rafaelromcar-parabol rafaelromcar-parabol commented Jul 11, 2024

Description

Fixes #9852

https://www.loom.com/share/7f5ddf56c4594e1692e266d556d95298

Summary by CodeRabbit

  • Bug Fixes
    • Updated group colours in the ReflectPrompt table to correctly reflect threat levels.

@rafaelromcar-parabol rafaelromcar-parabol self-assigned this Jul 11, 2024
@rafaelromcar-parabol rafaelromcar-parabol linked an issue Jul 11, 2024 that may be closed by this pull request
1 task
Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

The change introduces a new migration script to update the colours in the ReflectPrompt table according to predefined threat levels. The up function adjusts the colours for different threat levels, while the down function reverts these changes. This ensures that the prompt colours in the pre-mortem template match the corresponding emoji colours, addressing an inconsistency reported by the team.

Changes

File Path Change Summary
packages/server/postgres/migrations/1720689742934_fixThreatLevelPromptColors.ts Introduces migration logic to update group colours in the ReflectPrompt table based on threat levels.

Assessment against linked issues

Objective Addressed Explanation
Prompt colours should match the prompt name emoji colours (#9852)

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7124ce7 and aa5a668.

Files selected for processing (1)
  • packages/server/postgres/migrations/1720689742934_fixThreatLevelPromptColors.ts (1 hunks)

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

@rafaelromcar-parabol rafaelromcar-parabol requested review from Dschoordsch and mattkrick and removed request for tianrunhe and Dschoordsch July 11, 2024 11:24

await r
.table('ReflectPrompt')
.filter({id: 'threatLevelPremortemTemplateSeverePrompt'})
Copy link
Member

Choose a reason for hiding this comment

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

-1 use get instead of filter, otherwise it won't use the index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and tested locally again both migrating up and down! Thanks for the correction!

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: 4

Comment on lines +24 to +41
export async function down() {
await connectRethinkDB()

await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateSeverePrompt')
.update({groupColor: '#66BC8C'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateElevatedPrompt')
.update({groupColor: '#FD6157'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateLowPrompt')
.update({groupColor: '#FFCC63'})
.run()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent error handling across migrations.

The same error handling improvement suggested for the up function should be applied here.

  } catch (e) {
    console.error('Error during migration:', e)
+   throw e
  }

Committable suggestion was skipped due to low confidence.


Optimize the revert process for efficiency.

Similar to the up function, consider batching these updates into a single transaction to improve performance.

-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateSeverePrompt').update({groupColor: '#66BC8C'}).run()
-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateElevatedPrompt').update({groupColor: '#FD6157'}).run()
-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateLowPrompt').update({groupColor: '#FFCC63'}).run()
+  await r.table('ReflectPrompt').getAll('threatLevelPremortemTemplateSeverePrompt', 'threatLevelPremortemTemplateElevatedPrompt', 'threatLevelPremortemTemplateLowPrompt').update(function(doc) {
+    return r.branch(
+      doc('id').eq('threatLevelPremortemTemplateSeverePrompt'), {groupColor: '#66BC8C'},
+      doc('id').eq('threatLevelPremortemTemplateElevatedPrompt'), {groupColor: '#FD6157'},
+      doc('id').eq('threatLevelPremortemTemplateLowPrompt'), {groupColor: '#FFCC63'}
+    )
+  }).run()
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
export async function down() {
await connectRethinkDB()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateSeverePrompt')
.update({groupColor: '#66BC8C'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateElevatedPrompt')
.update({groupColor: '#FD6157'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateLowPrompt')
.update({groupColor: '#FFCC63'})
.run()
await r.table('ReflectPrompt')
.getAll('threatLevelPremortemTemplateSeverePrompt', 'threatLevelPremortemTemplateElevatedPrompt', 'threatLevelPremortemTemplateLowPrompt')
.update(function(doc) {
return r.branch(
doc('id').eq('threatLevelPremortemTemplateSeverePrompt'), {groupColor: '#66BC8C'},
doc('id').eq('threatLevelPremortemTemplateElevatedPrompt'), {groupColor: '#FD6157'},
doc('id').eq('threatLevelPremortemTemplateLowPrompt'), {groupColor: '#FFCC63'}
)
})
.run()

Comment on lines +4 to +21
export async function up() {
await connectRethinkDB()

await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateSeverePrompt')
.update({groupColor: '#FD6157'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateElevatedPrompt')
.update({groupColor: '#FFCC63'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateLowPrompt')
.update({groupColor: '#66BC8C'})
.run()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider batch updating for efficiency.

Updating each prompt separately results in multiple database connections and transactions, which is less efficient. Consider batching these updates into a single transaction to improve performance.

-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateSeverePrompt').update({groupColor: '#FD6157'}).run()
-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateElevatedPrompt').update({groupColor: '#FFCC63'}).run()
-  await r.table('ReflectPrompt').get('threatLevelPremortemTemplateLowPrompt').update({groupColor: '#66BC8C'}).run()
+  await r.table('ReflectPrompt').getAll('threatLevelPremortemTemplateSeverePrompt', 'threatLevelPremortemTemplateElevatedPrompt', 'threatLevelPremortemTemplateLowPrompt').update(function(doc) {
+    return r.branch(
+      doc('id').eq('threatLevelPremortemTemplateSeverePrompt'), {groupColor: '#FD6157'},
+      doc('id').eq('threatLevelPremortemTemplateElevatedPrompt'), {groupColor: '#FFCC63'},
+      doc('id').eq('threatLevelPremortemTemplateLowPrompt'), {groupColor: '#66BC8C'}
+    )
+  }).run()
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
export async function up() {
await connectRethinkDB()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateSeverePrompt')
.update({groupColor: '#FD6157'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateElevatedPrompt')
.update({groupColor: '#FFCC63'})
.run()
await r
.table('ReflectPrompt')
.get('threatLevelPremortemTemplateLowPrompt')
.update({groupColor: '#66BC8C'})
.run()
export async function up() {
await connectRethinkDB()
await r.table('ReflectPrompt').getAll('threatLevelPremortemTemplateSeverePrompt', 'threatLevelPremortemTemplateElevatedPrompt', 'threatLevelPremortemTemplateLowPrompt').update(function(doc) {
return r.branch(
doc('id').eq('threatLevelPremortemTemplateSeverePrompt'), {groupColor: '#FD6157'},
doc('id').eq('threatLevelPremortemTemplateElevatedPrompt'), {groupColor: '#FFCC63'},
doc('id').eq('threatLevelPremortemTemplateLowPrompt'), {groupColor: '#66BC8C'}
)
}).run()

Improve error handling by rethrowing the error.

As noted in previous comments, the function logs the error but does not rethrow it, which might make it harder to debug issues in a larger application.

  } catch (e) {
    console.error('Error during migration:', e)
+   throw e
  }

Committable suggestion was skipped due to low confidence.

@rafaelromcar-parabol
Copy link
Contributor Author

Question @mattkrick: what about the migrations and their order? This fix adds a migration, but there have been new migrations added to master since then 🤔 what do you usually do when that happens? rebase, merge master into the branch? recreate the migration after rebasing/merging? just merge the branch into master like it is?

@Dschoordsch
Copy link
Contributor

@rafaelromcar-parabol you need to rename the migration so it is newer than anything on master before you merge. I usually just create a new migration and copy and paste, but there might be a more elegant solution.

@mattkrick
Copy link
Member

i usually down-migrate, rename, then up-migrate. no perfect way to do it, distributed state management is hard!

@mattkrick mattkrick merged commit 0287026 into master Jul 17, 2024
7 checks passed
@mattkrick mattkrick deleted the fix/9852-fix-pre-mortem-template-colours branch July 17, 2024 19:54
@github-actions github-actions bot mentioned this pull request Jul 17, 2024
24 tasks
@rafaelromcar-parabol
Copy link
Contributor Author

Thanks for the tips! ❤️ and thanks for merging the branch!

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.

Fix pre-mortem template colours
3 participants