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

🔧 Add title column to DocVersion model in Prisma schema and corresponding SQL migrations #949

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

MH4GF
Copy link
Member

@MH4GF MH4GF commented Mar 21, 2025

Issue

  • resolve:

Why is this change needed?

Doc update retained content, but not title.

What would you like reviewers to focus on?

Testing Verification

What was done

🤖 Generated by PR Agent at 5c88216

  • Added a title column to the DocVersion model in the Prisma schema.
  • Updated SQL migrations to include the new title column.
  • Adjusted permissions and schema for DocVersion table in Supabase.

Detailed Changes

Relevant files
Enhancement
migration.sql
Add `title` column to `DocVersion` table                                 

frontend/packages/db/prisma/migrations/20250321012007_add_title_to_doc_version/migration.sql

  • Added a new title column to the DocVersion table.
  • Included a warning about adding a required column without a default
    value.
  • +8/-0     
    schema.prisma
    Update Prisma schema with `title` field                                   

    frontend/packages/db/prisma/schema.prisma

  • Added a title field to the DocVersion model.
  • Ensured the title field is of type String.
  • +2/-1     
    20250321012022_add_title_to_doc_version.sql
    Add `title` column and update permissions in Supabase       

    frontend/packages/db/supabase/migrations/20250321012022_add_title_to_doc_version.sql

  • Added a title column to the DocVersion table.
  • Updated permissions for Doc and DocVersion tables.
  • Adjusted schema to reflect the new column.
  • +87/-0   

    Additional Notes


    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    vercel bot commented Mar 21, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 7:09am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 7:09am
    4 Skipped Deployments
    Name Status Preview Comments Updated (UTC)
    liam-docs ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2025 7:09am
    test-liam-app ⬜️ Ignored (Inspect) Mar 21, 2025 7:09am
    test-liam-docs ⬜️ Ignored (Inspect) Mar 21, 2025 7:09am
    test-liam-erd-sample ⬜️ Ignored (Inspect) Mar 21, 2025 7:09am

    Copy link

    supabase bot commented Mar 21, 2025

    Updates to Preview Branch (add-title-to-docs-version) ↗︎

    Deployments Status Updated
    Database Fri, 21 Mar 2025 06:55:56 UTC
    Services Fri, 21 Mar 2025 06:55:56 UTC
    APIs Fri, 21 Mar 2025 06:55:56 UTC

    Tasks are run on every commit but only new migration files are pushed.
    Close and reopen this PR if you want to apply changes from existing seed or migration files.

    Tasks Status Updated
    Configurations Fri, 21 Mar 2025 06:56:06 UTC
    Migrations Fri, 21 Mar 2025 06:56:06 UTC
    Seeding Fri, 21 Mar 2025 06:56:06 UTC
    Edge Functions Fri, 21 Mar 2025 06:56:07 UTC

    View logs for this Workflow Run ↗︎.
    Learn more about Supabase for Git ↗︎.

    Copy link

    The schema changes provided indicate an important modification to the DocVersion model, specifically the addition of a new non-nullable title column. Here’s a comprehensive review of the changes:

    1. Addition of title Column: The new column title of type TEXT has been added to the DocVersion table. This change is significant as it allows for a title to be associated with each document version, which can enhance clarity and usability when referencing different versions of documents. However, it is crucial to note that this column is NOT NULL, which means every existing and future record must have a title assigned.

    2. Potential Migration Issues: The migration script comments highlight a critical concern: the addition of a NOT NULL column without a default value and while the table is potentially non-empty can lead to errors. If the DocVersion table already contains records, the migration would fail unless a default value is specified or the existing records are updated to include a title before the migration is executed. It is recommended to either provide a default title or to ensure that all existing records are updated to have a valid title prior to executing this migration.

    3. Schema Definition Update: The Prisma schema file has been updated accordingly to reflect the new column in the DocVersion model. This change is well-documented, ensuring that anyone reviewing the schema will understand the structural change made to the model.

    4. Revocation of Permissions: The migration scripts also include extensive revocation of permissions on both the Doc and DocVersion tables for various user roles (anon, authenticated, service_role). This indicates a move towards stricter security measures, which is prudent when altering schemas that may expose sensitive information. However, it is essential to ensure that the necessary permissions are re-granted or adjusted for the appropriate roles after the migration to prevent unintended access issues.

    5. Impact on Application Logic: The addition of the title field will likely impact any application logic that interacts with the DocVersion model. Developers will need to ensure that any creation or update operations include a title. This may involve updating forms, APIs, or other interfaces where users input or retrieve document versions.

    6. Documentation and Communication: It would be beneficial to document these changes thoroughly and communicate them to the development team. This includes updating any related documentation on how to use the title field and revising any tests that may be affected by this schema change.

    7. Testing: After implementing the migration, it is critical to run tests to verify that all functionalities involving DocVersion operate as expected. This includes checking for any edge cases where title may not be provided and ensuring that the application handles these cases gracefully.

    In conclusion, while the addition of the title column is a valuable enhancement to the DocVersion model, careful consideration needs to be given to the migration process, especially regarding existing records and permissions. Adequate testing and documentation will be essential to ensure a smooth transition and to maintain the integrity of the database schema.

    Migration URL: https://liam-erd-web.vercel.app/app/projects/6/migrations/68

    Copy link

    The proposed schema changes introduce a new title column to the DocVersion table, which is marked as NOT NULL. While this modification can enhance the clarity and usability of the DocVersion model, several critical considerations need to be addressed:

    1. Column Addition Without Default Value: The migration script for adding the title column to the DocVersion table does not include a default value. This can lead to issues if there are existing records in the table since PostgreSQL will not allow a NOT NULL column to be added to a non-empty table without providing a default. To avoid potential migration errors, it's advisable to either:

      • Add the column with a default value (e.g., an empty string or a placeholder like "Untitled").
      • Temporarily allow the column to be NULL, populate it for existing rows, and then alter it to NOT NULL afterward.
    2. Impact on Existing Data: If the DocVersion table already contains data, the addition of a non-nullable column could result in a migration failure. It's crucial to ensure the data integrity and handle existing records appropriately before applying this migration.

    3. Modification in Schema Definition: The Prisma schema has been updated to reflect the new title field in the DocVersion model. This is a necessary step to maintain consistency between the database schema and the application layer. However, ensure that the application logic is updated accordingly to handle the title when creating or updating DocVersion entries.

    4. Revocation of Permissions: The Supabase migration script revokes various permissions (select, insert, update, delete) for different roles (anon, authenticated, service_role) on both Doc and DocVersion tables. While restricting permissions is often necessary for security purposes, care must be taken to ensure that authorized users and roles retain the necessary access to perform their tasks. A review of the application’s role-based access control (RBAC) is recommended to confirm that essential functionalities are not hindered.

    5. Potential for Future Schema Changes: As the application evolves, consider how future changes to the DocVersion table might be managed. Establishing a clear migration strategy, including handling existing data and maintaining backward compatibility, will be beneficial for ongoing development.

    6. Testing and Rollback Strategy: Before deploying these changes to production, it's essential to thoroughly test the migration in a staging environment. Additionally, plan a rollback strategy in case the migration introduces unforeseen issues.

    7. Documentation: Finally, it would be beneficial to document this schema change in your project’s development notes, including the rationale for the change, its expected benefits, and any necessary migration steps for existing data. This will aid any developers who work on the project in the future.

    In summary, while the addition of the title column to the DocVersion table is a positive step towards improving the schema, careful attention must be paid to existing data, migration execution, permission management, and documentation to ensure a smooth transition.

    Migration URL: https://liam-app-git-staging-route-06-core.vercel.app/app/projects/4/migrations/17

    @MH4GF MH4GF marked this pull request as ready for review March 21, 2025 07:04
    @MH4GF MH4GF requested a review from a team as a code owner March 21, 2025 07:04
    @MH4GF MH4GF requested review from hoshinotsuyoshi, FunamaYukina, junkisai, NoritakaIkeda and sasamuku and removed request for a team March 21, 2025 07:04
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Data Migration

    The migration adds a required column without a default value, which will fail if the table already contains data. Consider adding a data migration strategy or default value.

    - Added the required column `title` to the `DocVersion` table without a default value. This is not possible if the table is not empty.
    Field Reordering

    The createdAt field was moved from its original position to after the content field. This reordering doesn't affect functionality but might impact code readability and consistency.

    title     String
    content   String
    createdAt DateTime  @default(now())

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add default value

    Adding a required column without a default value to a table that may contain
    data will cause the migration to fail. Provide a default value for the new title
    column or make it nullable.

    frontend/packages/db/prisma/migrations/20250321012007_add_title_to_doc_version/migration.sql [7-8]

     -- AlterTable
    -ALTER TABLE "DocVersion" ADD COLUMN     "title" TEXT NOT NULL;
    +ALTER TABLE "DocVersion" ADD COLUMN     "title" TEXT NOT NULL DEFAULT '';
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This suggestion addresses a critical issue that would cause the migration to fail. Adding a required column without a default value to an existing table with data will result in a database error, as noted in the warning comment in the migration file itself.

    High
    • More

    Copy link
    Member

    @NoritakaIkeda NoritakaIkeda left a comment

    Choose a reason for hiding this comment

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

    LGTM!

    @NoritakaIkeda NoritakaIkeda added this pull request to the merge queue Mar 21, 2025
    Merged via the queue into main with commit 421108e Mar 21, 2025
    22 checks passed
    @NoritakaIkeda NoritakaIkeda deleted the add-title-to-docs-version branch March 21, 2025 07:11
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants