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: remove links between question instances and (detail) responses #4141

Merged
merged 5 commits into from
Aug 2, 2024

Conversation

sjschlapbach
Copy link
Member

@sjschlapbach sjschlapbach commented Jul 15, 2024

This pull request makes the following changes to the database scheme (incl. migration):

  • Remove links between QuestionInstance (only used in live quiz) and QuestionResponse and QuestionResponseDetails - all corresponding ids are set to null already
  • Make the links between QuestionResponse / QuestionResponseDetail and ElementInstance required, since response objects without this link cannot be associated with a question / flashcard / ... anyway and are therefore not really informative - all of the corresponding ids are defined (not response with null as elementInstanceId)
  • Change the deletion / updating logic such that responses are deleted alongside the corresponding ElementInstance, since there might be responses without an assigned question otherwise, which does not make sense, since the results cannot be interpreted without the question.

Summary by CodeRabbit

  • New Features

    • Enhanced database schema for improved data integrity by making elementInstanceId a required field in the QuestionResponse and QuestionResponseDetail tables.
  • Bug Fixes

    • Removed the unnecessary questionInstanceId field from the QuestionResponse and QuestionResponseDetail models to streamline relationships.
  • Refactor

    • Updated relationships to establish a mandatory connection with ElementInstance, enhancing the overall structure of the data model.

@sjschlapbach sjschlapbach requested a review from rschlaefli July 15, 2024 08:36
Copy link

cypress bot commented Jul 15, 2024



Test summary

38 0 0 0Flakiness 1


Run details

Project klicker-uzh
Status Passed
Commit 4a1f43d ℹ️
Started Jul 31, 2024 1:49 AM
Ended Jul 31, 2024 1:57 AM
Duration 07:23 💡
OS Linux Ubuntu -
Browser Electron 118

View run in Cypress Cloud ➡️


Flakiness

cypress/e2e/G-microlearning-workflow.cy.ts Flakiness
1 Different microlearning workflows > converts a seeded past microlearning into a practice quiz

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

@coveralls
Copy link

coveralls commented Jul 15, 2024

Coverage Status

coverage: 68.493%. remained the same
when pulling 1d04c76 on RemoveQuestionInstanceResponsesLinks
into 5dd36e4 on v3.

Copy link
Member

@rschlaefli rschlaefli left a comment

Choose a reason for hiding this comment

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

Agree with the change and makes the schema cleaner and data consistent. However, to be discussed whether we want to delete element instances and thus trigger cascading delete (or whether we remove cascading delete and actually want to have a transaction fail when an instance is deleted but responses are still around?), or whether we keep element instances around even if the element they correspond to is deleted (or even also for quizzes that were published but are deleted?), thus keeping leaderboards and responses consistent (as the instance should contain all data necessary to know what it was about)? Especially if we want to do timelines, audit logs, and such things, we want to make sure that they cannot change after participants have seen them, and responses should be consistent with such derived data (meaning responses should basically never be deleted).

Copy link

coderabbitai bot commented Jul 31, 2024

Walkthrough

This migration overhaul enhances the database schema by removing the questionInstanceId from the QuestionResponse and QuestionResponseDetail tables. This change simplifies relationships, making the elementInstanceId a mandatory field linked to the ElementInstance table. The migration improves data integrity and consistency while restructuring foreign key constraints and ensuring the relationships are updated to reflect these changes.

Changes

Files Change Summary
packages/prisma/src/prisma/migrations/... Dropped questionInstanceId from QuestionResponse and QuestionResponseDetail, modified elementInstanceId to be required, and updated foreign key constraints.
packages/prisma/src/prisma/schema.prisma Removed optional relations to QuestionInstance, made elementInstance relationships mandatory, and updated unique constraints accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant Database

    User->>App: Submit Question Response
    App->>Database: Save Response with Element Instance
    Database-->>App: Confirmation
    App-->>User: Response Saved
Loading

Poem

🐰 In fields where questions once did roam,
A change has come to make it home.
No more instances to weigh us down,
Just elements now wear the crown.
A leap for clarity, bright and bold,
In every response, new tales unfold! 🌼


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

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5dd36e4 and 1d04c76.

Files selected for processing (2)
  • packages/prisma/src/prisma/migrations/20240715083055_drop_question_instance_response_links/migration.sql (1 hunks)
  • packages/prisma/src/prisma/schema.prisma (3 hunks)
Additional comments not posted (11)
packages/prisma/src/prisma/migrations/20240715083055_drop_question_instance_response_links/migration.sql (9)

10-11: Approved: Dropping foreign key constraint.

Dropping the foreign key constraint QuestionResponse_elementInstanceId_fkey is necessary for modifying the elementInstanceId column.


13-14: Approved: Dropping foreign key constraint.

Dropping the foreign key constraint QuestionResponse_questionInstanceId_fkey is necessary as the questionInstanceId column is being removed.


16-17: Approved: Dropping foreign key constraint.

Dropping the foreign key constraint QuestionResponseDetail_elementInstanceId_fkey is necessary for modifying the elementInstanceId column.


19-20: Approved: Dropping foreign key constraint.

Dropping the foreign key constraint QuestionResponseDetail_questionInstanceId_fkey is necessary as the questionInstanceId column is being removed.


22-23: Approved: Dropping index.

Dropping the index QuestionResponse_participantId_questionInstanceId_key is necessary as the questionInstanceId column is being removed.


33-34: Approved: Adding foreign key constraint.

Adding the foreign key constraint QuestionResponse_elementInstanceId_fkey ensures referential integrity with the ElementInstance table.


36-37: Approved: Adding foreign key constraint.

Adding the foreign key constraint QuestionResponseDetail_elementInstanceId_fkey ensures referential integrity with the ElementInstance table.


29-31: Approved: Altering QuestionResponseDetail table.

Dropping the questionInstanceId column and setting the elementInstanceId column to NOT NULL is necessary for the schema changes.

Ensure that there are no existing NULL values in the elementInstanceId column before applying this change.


25-27: Approved: Altering QuestionResponse table.

Dropping the questionInstanceId column and setting the elementInstanceId column to NOT NULL is necessary for the schema changes.

Ensure that there are no existing NULL values in the elementInstanceId column before applying this change.

packages/prisma/src/prisma/schema.prisma (2)

1015-1016: Approved: Changes to QuestionResponse model.

The removal of the questionInstanceId field and making the elementInstance relationship mandatory with ON DELETE and ON UPDATE CASCADE is correctly reflected.


1042-1043: Approved: Changes to QuestionResponseDetail model.

The removal of the questionInstanceId field and making the elementInstance relationship mandatory with ON DELETE and ON UPDATE CASCADE is correctly reflected.

@rschlaefli rschlaefli merged commit 1c3d1ba into v3 Aug 2, 2024
12 of 14 checks passed
@rschlaefli rschlaefli deleted the RemoveQuestionInstanceResponsesLinks branch August 2, 2024 20:33
Copy link

cypress bot commented Aug 2, 2024



Test summary

38 0 0 0Flakiness 0


Run details

Project klicker-uzh
Status Passed
Commit 1c3d1ba
Started Aug 2, 2024 8:41 PM
Ended Aug 2, 2024 8:48 PM
Duration 07:19 💡
OS Linux Ubuntu -
Browser Electron 118

View run in Cypress Cloud ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants