Skip to content

Commit 81a38e9

Browse files
authored
Merge pull request #1511 from MTES-MCT/issue/2728
#minor (2728) Supprimer l'espace d'entraide
2 parents 8dfcdb2 + 2a41b11 commit 81a38e9

201 files changed

Lines changed: 119 additions & 8832 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
module.exports = {
2+
async up(queryInterface) {
3+
const transaction = await queryInterface.sequelize.transaction();
4+
5+
try {
6+
// 1. Delete rows from attachments referenced by question_attachments and answer_attachments.
7+
// A DROP TABLE does not fire ON DELETE triggers, so this DELETE is required to trigger
8+
// archive_deleted_attachment_before_deletion (copy into attachments_archives before removal),
9+
// exactly like any other attachment deletion in the app (see services/attachment/cleanArchives.ts).
10+
await queryInterface.sequelize.query(
11+
`DELETE FROM attachments
12+
WHERE attachment_id IN (SELECT fk_attachment FROM question_attachments)
13+
OR attachment_id IN (SELECT fk_attachment FROM answer_attachments)`,
14+
{ transaction },
15+
);
16+
17+
// 2. Drop triggers and constraints from question_attachments and answer_attachments
18+
await Promise.all([
19+
queryInterface.sequelize.query(
20+
'DROP TRIGGER IF EXISTS delete_actual_attachment ON question_attachments',
21+
{ transaction },
22+
),
23+
queryInterface.sequelize.query(
24+
'DROP TRIGGER IF EXISTS delete_actual_attachment ON answer_attachments',
25+
{ transaction },
26+
),
27+
]);
28+
29+
await Promise.all([
30+
queryInterface.removeConstraint('question_attachments', 'fk_question', { transaction }),
31+
queryInterface.removeConstraint('question_attachments', 'fk_attachment', { transaction }),
32+
queryInterface.removeConstraint('answer_attachments', 'fk_answer', { transaction }),
33+
queryInterface.removeConstraint('answer_attachments', 'fk_attachment', { transaction }),
34+
]);
35+
36+
// 3. Drop question_attachments and answer_attachments tables
37+
await Promise.all([
38+
queryInterface.dropTable('question_attachments', { transaction }),
39+
queryInterface.dropTable('answer_attachments', { transaction }),
40+
]);
41+
42+
// 4. Drop question_to_tags table (FK vers questions et question_tags)
43+
await Promise.all([
44+
queryInterface.removeConstraint('question_to_tags', 'fk_question_question_to_tags', { transaction }),
45+
queryInterface.removeConstraint('question_to_tags', 'fk_question_tag_question_to_tags', { transaction }),
46+
]);
47+
await queryInterface.dropTable('question_to_tags', { transaction });
48+
49+
// 5. Drop user_question_subscriptions table (FK vers users et questions)
50+
await Promise.all([
51+
queryInterface.removeConstraint('user_question_subscriptions', 'fk__user_question_subscriptions__user', { transaction }),
52+
queryInterface.removeConstraint('user_question_subscriptions', 'fk__user_question_subscriptions__question', { transaction }),
53+
]);
54+
await queryInterface.dropTable('user_question_subscriptions', { transaction });
55+
56+
// 6. Drop answers table (FK vers questions)
57+
await Promise.all([
58+
queryInterface.removeConstraint('answers', 'fk_answers_question', { transaction }),
59+
queryInterface.removeConstraint('answers', 'fk_answer_creator', { transaction }),
60+
]);
61+
await queryInterface.dropTable('answers', { transaction });
62+
63+
// 7. Drop questions table (FK vers users)
64+
await queryInterface.removeConstraint('questions', 'fk_question_creator', { transaction });
65+
await queryInterface.dropTable('questions', { transaction });
66+
67+
// 8. Drop question_tags table
68+
await queryInterface.removeConstraint('question_tags', 'uk_question_tags_name', { transaction });
69+
await queryInterface.dropTable('question_tags', { transaction });
70+
71+
// 9. Delete email subscription
72+
await queryInterface.sequelize.query(
73+
'DELETE FROM user_email_unsubscriptions WHERE email_subscription = \'community_new_question\'',
74+
{ transaction },
75+
);
76+
77+
await transaction.commit();
78+
} catch (error) {
79+
await transaction.rollback();
80+
throw error;
81+
}
82+
},
83+
84+
async down() {
85+
throw new Error('Cette migration est irréversible : les tables questions/answers et leurs données ont été supprimées définitivement.');
86+
},
87+
};

packages/api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"ts-node": "^10.9.1",
7070
"tsc-alias": "^1.4.0",
7171
"typescript": "^5.0.0",
72-
"uuid": "^14.0.0",
72+
"uuid": "^9.0.0",
7373
"validator": "^13.15.22"
7474
},
7575
"devDependencies": {
@@ -148,4 +148,4 @@
148148
"emails:preview": "ts-node server/mails/preview.ts",
149149
"test:activity-summary": "ts-node test/mails/testActivitySummary.ts"
150150
}
151-
}
151+
}

packages/api/server/config/email_subscriptions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ export default [
44
'action_comment_notification',
55
'shantytown_closure',
66
'shantytown_creation',
7-
'community_new_question',
87
];

packages/api/server/controllers/question/create/question.create.route.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/api/server/controllers/question/create/question.create.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/api/server/controllers/question/create/question.create.validator.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/api/server/controllers/question/createAnswer/question.createAnswer.route.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/api/server/controllers/question/createAnswer/question.createAnswer.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/api/server/controllers/question/createAnswer/question.createAnswer.validator.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/api/server/controllers/question/delete/question.delete.route.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)