mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: Add migration to assign default incident roles to existing projects
This commit is contained in:
@@ -935,7 +935,7 @@ export class ProjectService extends DatabaseService<Model> {
|
||||
return createdItem;
|
||||
}
|
||||
|
||||
private async addDefaultIncidentRoles(createdItem: Model): Promise<Model> {
|
||||
public async addDefaultIncidentRoles(createdItem: Model): Promise<Model> {
|
||||
let incidentCommander: IncidentRole = new IncidentRole();
|
||||
incidentCommander.name = "Incident Commander";
|
||||
incidentCommander.description =
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import DataMigrationBase from "./DataMigrationBase";
|
||||
import LIMIT_MAX, { LIMIT_INFINITY } from "Common/Types/Database/LimitMax";
|
||||
import ProjectService from "Common/Server/Services/ProjectService";
|
||||
import IncidentRoleService from "Common/Server/Services/IncidentRoleService";
|
||||
import Project from "Common/Models/DatabaseModels/Project";
|
||||
import IncidentRole from "Common/Models/DatabaseModels/IncidentRole";
|
||||
|
||||
export default class AddDefaultIncidentRolesToExistingProjects extends DataMigrationBase {
|
||||
public constructor() {
|
||||
super("AddDefaultIncidentRolesToExistingProjects");
|
||||
}
|
||||
|
||||
public override async migrate(): Promise<void> {
|
||||
// Get all projects
|
||||
const projects: Array<Project> = await ProjectService.findBy({
|
||||
query: {},
|
||||
select: {
|
||||
_id: true,
|
||||
},
|
||||
skip: 0,
|
||||
limit: LIMIT_INFINITY,
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (const project of projects) {
|
||||
// Check if this project already has incident roles
|
||||
const existingRoles: Array<IncidentRole> =
|
||||
await IncidentRoleService.findBy({
|
||||
query: {
|
||||
projectId: project.id!,
|
||||
},
|
||||
select: {
|
||||
_id: true,
|
||||
},
|
||||
skip: 0,
|
||||
limit: 1,
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Only add default roles if none exist
|
||||
if (existingRoles.length === 0) {
|
||||
await ProjectService.addDefaultIncidentRoles(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override async rollback(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ import AddOnCallNotificationForUsers from "./AddOnCallNotificationForUsers";
|
||||
import StartOnCallUserTimeLog from "./StartOnCallUserTimeLog";
|
||||
import LowercaseDomains from "./LowercaseDomains";
|
||||
import AddAttributeKeysColumnToTelemetryTables from "./AddAttributeKeysColumnToTelemetryTables";
|
||||
import AddDefaultIncidentRolesToExistingProjects from "./AddDefaultIncidentRolesToExistingProjects";
|
||||
|
||||
// This is the order in which the migrations will be run. Add new migrations to the end of the array.
|
||||
|
||||
@@ -110,6 +111,7 @@ const DataMigrations: Array<DataMigrationBase> = [
|
||||
new StartOnCallUserTimeLog(),
|
||||
new LowercaseDomains(),
|
||||
new AddAttributeKeysColumnToTelemetryTables(),
|
||||
new AddDefaultIncidentRolesToExistingProjects(),
|
||||
];
|
||||
|
||||
export default DataMigrations;
|
||||
|
||||
Reference in New Issue
Block a user