Skip to content
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,19 @@
-- remove exists duplicate entries from database
DELETE FROM note_teams
WHERE id IN (
SELECT id
FROM (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY note_id, user_id
ORDER BY id
) AS row_num
FROM note_teams
) AS duplicates
WHERE duplicates.row_num > 1
);

-- adds unique index
CREATE UNIQUE INDEX IF NOT EXISTS note_teams_note_id_user_id_unique_idx
ON public.note_teams (note_id, user_id);
6 changes: 0 additions & 6 deletions src/presentation/http/router/noteSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,6 @@ describe('NoteSettings API', () => {
creatorId: user.id,
});

await global.db.insertNoteTeam({
noteId: note.id,
userId: user.id,
role: MemberRole.Write,
});

const accessToken = global.auth(user.id);

const response = await global.api?.fakeRequest({
Expand Down
7 changes: 7 additions & 0 deletions src/repository/storage/postgres/orm/sequelize/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export default class TeamsSequelizeStorage {
tableName: this.tableName,
sequelize: this.database,
timestamps: false,
indexes: [
// Create a unique index on noteId and userId
{
unique: true,
fields: ['note_id', 'user_id'],
},
],
});
}

Expand Down
Loading