Conversation
There was a problem hiding this comment.
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.creatortoNOT NULL. - Updates the shared
RecordDataModelTypeORM relation metadata forcreatorto 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: falseonRecordDataModel.creatoraffects every entity that extendsRecordDataModel, not just notes. Many tables in the SQL migrations still definecreatoras nullable (e.g.,Create-notes.sqland 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 forsims.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;
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| 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 () => { |
There was a problem hiding this comment.
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
andrewsignori-aot
left a comment
There was a problem hiding this comment.
Thanks for checking PROD data. Please take a look at the latest comments.
| if (!holdRestriction) { | ||
| throw new Error( | ||
| "Expected a HOLD restriction to be created for the student.", | ||
| ); | ||
| } |
There was a problem hiding this comment.
Please use the expect to execute the assertions.
| noteType: NoteType.Restriction, | ||
| creator: { | ||
| id: systemUserId, | ||
| userName: expect.any(String), |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
The comment must be adjusted to remove the "ON DELETE behavior", right?
andrewsignori-aot
left a comment
There was a problem hiding this comment.
Thanks for the further investigation on PROD and for making the changes. Only minor comments, hence approving it 👍
|



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