Skip to content

#5154 - Set notes creator not null#5782

Merged
tiago-graf merged 23 commits intomainfrom
feature/#5154-set-notes-creator
Feb 20, 2026
Merged

#5154 - Set notes creator not null#5782
tiago-graf merged 23 commits intomainfrom
feature/#5154-set-notes-creator

Conversation

@tiago-graf
Copy link
Copy Markdown
Collaborator

Summary

Creates migration to alter notes table setting the column creator to NOT NULL.
No data was found where the creator is null, so there is not need to update any records/code.

Migration/Rollback Test

image

@tiago-graf tiago-graf requested a review from Copilot February 17, 2026 23:00
@tiago-graf tiago-graf self-assigned this Feb 17, 2026
@tiago-graf tiago-graf added DB DB migration involved Backend Used by the dependabot pull requests to identify PRs related to the backend. labels Feb 17, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enforces that sims.notes.creator is not nullable, strengthening auditability/data integrity for notes in the SIMS database layer.

Changes:

  • Adds a DB migration (and rollback) to set sims.notes.creator to NOT NULL.
  • Updates the shared RecordDataModel TypeORM relation metadata for creator to be non-nullable.
  • Adds a TypeORM migration wrapper to execute the SQL scripts.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sources/packages/backend/libs/sims-db/src/entities/record.model.ts Changes RecordDataModel.creator relation to nullable: false at the ORM level.
sources/packages/backend/apps/db-migrations/src/sql/Notes/Set-notes-creator-not-null.sql Alters sims.notes.creator to NOT NULL.
sources/packages/backend/apps/db-migrations/src/sql/Notes/Rollback-set-notes-creator-not-null.sql Rollback script to drop the NOT NULL constraint on sims.notes.creator.
sources/packages/backend/apps/db-migrations/src/migrations/1771367806224-SetNotesCreatorNotNull.ts TypeORM migration that runs the forward/rollback SQL scripts.
Comments suppressed due to low confidence (1)

sources/packages/backend/libs/sims-db/src/entities/record.model.ts:15

  • Setting nullable: false on RecordDataModel.creator affects every entity that extends RecordDataModel, not just notes. Many tables in the SQL migrations still define creator as nullable (e.g., Create-notes.sql and several others), and some comments explicitly state NULL means "created by system". This ORM-level change will make the entity metadata inconsistent with the actual schema/expected behavior and may break inserts/updates for records created without a user. Consider reverting this change in the base class and enforcing NOT NULL only for sims.notes.creator (DB-only), or introduce a separate base model for entities that require a non-null creator.
  @ManyToOne(() => User, { eager: false, nullable: false })
  @JoinColumn({
    name: ColumnNames.Creator,
    referencedColumnName: ColumnNames.ID,
  })
  creator: User;

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

tiago-graf and others added 3 commits February 19, 2026 09:19
@tiago-graf tiago-graf marked this pull request as ready for review February 19, 2026 19:57
@andrewsignori-aot andrewsignori-aot self-requested a review February 19, 2026 20:01
Copy link
Copy Markdown
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Nice work, minor comments/clarifications.

expect(updatedSFASApplication.wthdProcessed).toBe(false);
});

it("Should create a BCSC student with HOLD restriction and note when SFAS partial match exists and note should have a creator.", async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we renamed the test as below? The creator is the target of this ticket but the E2E itself should not have the creator as target to be tested. Does it make sense?

Should create a BCSC student with HOLD restriction and note when SFAS partial match exists

Copy link
Copy Markdown
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Thanks for checking PROD data. Please take a look at the latest comments.

Comment thread sources/packages/backend/libs/test-utils/src/factories/student.ts Outdated
Comment on lines +314 to +318
if (!holdRestriction) {
throw new Error(
"Expected a HOLD restriction to be created for the student.",
);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use the expect to execute the assertions.

noteType: NoteType.Restriction,
creator: {
id: systemUserId,
userName: expect.any(String),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to select the userName if it will not be asserted. Since the name is known, it should be either asserted or removed.

SET
NOT NULL;

-- Recreate the foreign key with an ON DELETE behavior compatible with NOT NULL.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The comment must be adjusted to remove the "ON DELETE behavior", right?

Copy link
Copy Markdown
Collaborator

@andrewsignori-aot andrewsignori-aot left a comment

Choose a reason for hiding this comment

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

Thanks for the further investigation on PROD and for making the changes. Only minor comments, hence approving it 👍

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 20.42% ( 4495 / 22015 )
Methods: 9.77% ( 262 / 2683 )
Lines: 24.62% ( 3847 / 15625 )
Branches: 10.41% ( 386 / 3707 )

@github-actions
Copy link
Copy Markdown

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 75.41% ( 1055 / 1399 )
Methods: 79.31% ( 115 / 145 )
Lines: 78.79% ( 769 / 976 )
Branches: 61.51% ( 171 / 278 )

@github-actions
Copy link
Copy Markdown

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 85.68% ( 1616 / 1886 )
Methods: 85% ( 187 / 220 )
Lines: 88.64% ( 1287 / 1452 )
Branches: 66.36% ( 142 / 214 )

@github-actions
Copy link
Copy Markdown

E2E SIMS API Coverage Report

Totals Coverage
Statements: 76.86% ( 9206 / 11977 )
Methods: 75.42% ( 1071 / 1420 )
Lines: 81.28% ( 6694 / 8236 )
Branches: 62.09% ( 1441 / 2321 )

@tiago-graf tiago-graf added this pull request to the merge queue Feb 20, 2026
Merged via the queue into main with commit fd6d895 Feb 20, 2026
22 checks passed
@tiago-graf tiago-graf deleted the feature/#5154-set-notes-creator branch February 20, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Used by the dependabot pull requests to identify PRs related to the backend. DB DB migration involved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants