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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {r} from 'rethinkdb-ts'
import connectRethinkDB from '../../database/connectRethinkDB'

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()
Comment on lines +4 to +21
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.

}

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()
Comment on lines +24 to +41
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()

}
Loading