diff --git a/server/migrations/20250810173939-remove-team-name-nullable.js b/server/migrations/20250810173939-remove-team-name-nullable.js new file mode 100644 index 0000000000..fd859f603c --- /dev/null +++ b/server/migrations/20250810173939-remove-team-name-nullable.js @@ -0,0 +1,23 @@ +"use strict"; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + // Update any NULL team names to "Wiki" before removing nullable constraint + await queryInterface.sequelize.query( + `UPDATE teams SET name = 'Wiki' WHERE name IS NULL;` + ); + + await queryInterface.changeColumn("teams", "name", { + type: Sequelize.STRING, + allowNull: false, + }); + }, + + async down(queryInterface, Sequelize) { + await queryInterface.changeColumn("teams", "name", { + type: Sequelize.STRING, + allowNull: true, + }); + }, +}; diff --git a/server/routes/api/teams/teams.test.ts b/server/routes/api/teams/teams.test.ts index 44c7f3d992..4e42b77fe2 100644 --- a/server/routes/api/teams/teams.test.ts +++ b/server/routes/api/teams/teams.test.ts @@ -225,6 +225,17 @@ describe("#team.update", () => { expect(res.status).toEqual(401); }); + it("should not allow setting team name to null", async () => { + const admin = await buildAdmin(); + const res = await server.post("/api/team.update", { + body: { + token: admin.getJwtToken(), + name: null, + }, + }); + expect(res.status).toEqual(400); + }); + it("should update default collection", async () => { const team = await buildTeam(); const admin = await buildAdmin({ teamId: team.id });