Skip to content

Create migration script for reporting #1316

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

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
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,22 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.sequelize.query(
`ALTER TYPE enum_files_source ADD VALUE 'Report';`,
{ transaction }
);
await transaction.commit();
} catch (error) {
await transaction.rollback();
throw error;
}
},

async down(queryInterface, Sequelize) {
// The enum value won't cause any issues if it is not removed
}
};
8 changes: 4 additions & 4 deletions Servers/models/file.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface File {
project_id: number;
uploaded_by: number;
uploaded_time: Date;
source: "Assessment tracker group" | "Compliance tracker group";
source: "Assessment tracker group" | "Compliance tracker group" | "Report";
}

export interface FileType {
Expand All @@ -18,7 +18,7 @@ export interface FileType {
uploaded_by: number;
uploaded_time: Date;
type: string;
source: "Assessment tracker group" | "Compliance tracker group";
source: "Assessment tracker group" | "Compliance tracker group" | "Report";
}

@Table({
Expand Down Expand Up @@ -60,9 +60,9 @@ export class FileModel extends Model<File> {
uploaded_time!: Date;

@Column({
type: DataType.ENUM("Assessment tracker group", "Compliance tracker group"),
type: DataType.ENUM("Assessment tracker group", "Compliance tracker group", "Report"),
})
source!: "Assessment tracker group" | "Compliance tracker group";
source!: "Assessment tracker group" | "Compliance tracker group" | "Report";

@Column({
type: DataType.STRING
Expand Down
2 changes: 1 addition & 1 deletion Servers/utils/fileUpload.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const uploadFile = async (
file: UploadedFile,
user_id: number,
project_framework_id: number,
source: "Assessment tracker group" | "Compliance tracker group",
source: "Assessment tracker group" | "Compliance tracker group" | "Report",
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM! Type definition correctly updated for 'Report' source

The type definition for the source parameter has been appropriately expanded to include the new "Report" option, maintaining consistency with the database migration and model changes.

Consider whether any downstream consumers of this function need to be updated to handle the new source type. If the source type affects file handling behavior elsewhere in the application, those areas might need updates as well.


🏁 Script executed:

#!/bin/bash
# Check for any other references to the source field that might need updating
rg -A 1 -B 1 "source: (\"Assessment tracker group\" \| \"Compliance tracker group\")" --type ts --glob "!Servers/utils/fileUpload.utils.ts" --glob "!Servers/models/file.model.ts"

Length of output: 176


🏁 Script executed:

#!/bin/bash
# Search for any mentions of the source literal values in TypeScript files
rg "Assessment tracker group" --type ts
rg "Compliance tracker group" --type ts

# Inspect the 'source' property definition in the file model to ensure it's updated
rg "source" -A2 -B2 Servers/models/file.model.ts

Length of output: 2570


Ensure ‘Report’ source is handled downstream

The type definition and model enum have been correctly expanded to include "Report", but a search across the codebase did not uncover any calls to uploadFile(..., "Report"):

  • Controllers (reporting.ctrl.ts, file.ctrl.ts) still only use "Assessment tracker group"
  • subControl.utils.ts only uses "Compliance tracker group"
  • No other TS files pass "Report" to uploadFile

Please add or update any controllers, services, or UI components that should upload files with the "Report" source to ensure this new option is actually used.

transaction: Transaction | null = null
) => {
const project = await sequelize.query(
Expand Down