Skip to content

Commit cbe9e48

Browse files
committed
* fix: Add missing enum_ value other where missing
* chore: update database dump
1 parent 374a78f commit cbe9e48

File tree

5 files changed

+112
-6
lines changed

5 files changed

+112
-6
lines changed

app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const StreamUpload = require('stream_upload');
3434
const notifications = require('./libs/notifications');
3535
const SlowDown = require('express-slow-down');
3636
const rateLimit = require('express-rate-limit')
37+
const which = require('which');
3738

3839
const app = express();
3940
app.set('redis', require('./libs/redis')(app));

db/config/database.sql

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ CREATE TYPE public."enum_Comments_deletedReasonType" AS ENUM (
6262
'spam',
6363
'hate',
6464
'netiquette',
65-
'duplicate'
65+
'duplicate',
66+
'other'
6667
);
6768

6869

@@ -138,7 +139,8 @@ CREATE TYPE public."enum_IdeaReports_moderatedReasonType" AS ENUM (
138139
'spam',
139140
'hate',
140141
'netiquette',
141-
'duplicate'
142+
'duplicate',
143+
'other'
142144
);
143145

144146

@@ -152,7 +154,8 @@ CREATE TYPE public."enum_IdeaReports_type" AS ENUM (
152154
'spam',
153155
'hate',
154156
'netiquette',
155-
'duplicate'
157+
'duplicate',
158+
'other'
156159
);
157160

158161

@@ -166,7 +169,8 @@ CREATE TYPE public."enum_Ideas_deletedReasonType" AS ENUM (
166169
'spam',
167170
'hate',
168171
'netiquette',
169-
'duplicate'
172+
'duplicate',
173+
'other'
170174
);
171175

172176

@@ -4213,4 +4217,6 @@ COPY public."SequelizeMeta" (name) FROM stdin;
42134217
20250131193905-draft-ideas.js
42144218
20250319122353-alter-reports-update-type.js
42154219
20250416191841-alter-topic-reports-update-type.js
4220+
20250415183735-alter-attachments-update-creator-id-relation.js
4221+
20250424201337-alter-idea-reports-update-type.js
42164222
\.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict';
2+
3+
/** @type {import('sequelize-cli').Migration} */
4+
module.exports = {
5+
async up(queryInterface) {
6+
// Check if the value already exists in the enum before adding it
7+
await queryInterface.sequelize.query(`
8+
DO $$
9+
BEGIN
10+
-- Check if 'other' value already exists in the enum
11+
IF NOT EXISTS (
12+
SELECT 1
13+
FROM pg_enum
14+
WHERE enumlabel = 'other'
15+
AND enumtypid = (
16+
SELECT oid
17+
FROM pg_type
18+
WHERE typname = 'enum_Ideas_deletedReasonType'
19+
)
20+
) THEN
21+
-- If it doesn't exist, add it
22+
ALTER TYPE "enum_Ideas_deletedReasonType" ADD VALUE 'other' AFTER 'duplicate';
23+
END IF;
24+
END
25+
$$;
26+
`);
27+
28+
await queryInterface.sequelize.query(`
29+
DO $$
30+
BEGIN
31+
-- Check if 'other' value already exists in the enum
32+
IF NOT EXISTS (
33+
SELECT 1
34+
FROM pg_enum
35+
WHERE enumlabel = 'other'
36+
AND enumtypid = (
37+
SELECT oid
38+
FROM pg_type
39+
WHERE typname = 'enum_Comments_deletedReasonType'
40+
)
41+
) THEN
42+
-- If it doesn't exist, add it
43+
ALTER TYPE "enum_Comments_deletedReasonType" ADD VALUE 'other' AFTER 'duplicate';
44+
END IF;
45+
END
46+
$$;
47+
`);
48+
49+
await queryInterface.sequelize.query(`
50+
DO $$
51+
BEGIN
52+
-- Check if 'other' value already exists in the enum
53+
IF NOT EXISTS (
54+
SELECT 1
55+
FROM pg_enum
56+
WHERE enumlabel = 'other'
57+
AND enumtypid = (
58+
SELECT oid
59+
FROM pg_type
60+
WHERE typname = 'enum_IdeaReports_moderatedReasonType'
61+
)
62+
) THEN
63+
-- If it doesn't exist, add it
64+
ALTER TYPE "enum_IdeaReports_moderatedReasonType" ADD VALUE 'other' AFTER 'duplicate';
65+
END IF;
66+
END
67+
$$;
68+
`);
69+
70+
await queryInterface.sequelize.query(`
71+
DO $$
72+
BEGIN
73+
-- Check if 'other' value already exists in the enum
74+
IF NOT EXISTS (
75+
SELECT 1
76+
FROM pg_enum
77+
WHERE enumlabel = 'other'
78+
AND enumtypid = (
79+
SELECT oid
80+
FROM pg_type
81+
WHERE typname = 'enum_IdeaReports_type'
82+
)
83+
) THEN
84+
-- If it doesn't exist, add it
85+
ALTER TYPE "enum_IdeaReports_type" ADD VALUE 'other' AFTER 'duplicate';
86+
END IF;
87+
END
88+
$$;
89+
`);
90+
},
91+
92+
async down() {
93+
console.log('NO ROLLBACK FOR THIS MIGRATION.');
94+
console.log('IF you want to revert this. You need to decide what to do with the data that has the new Report.type="other".');
95+
console.log('Once the data has been cleaned up, that is, no "other" is used, you need to recreate the ENUM without the "other" because at this point PG does not support droping values from ENUM');
96+
}
97+
};

db/models/Comment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module.exports = function (sequelize, DataTypes) {
3333
spam: 'spam', // contains spam or is unrelated to topic
3434
hate: 'hate', // contains hate speech
3535
netiquette: 'netiquette', // infringes (n)etiquette
36-
duplicate: 'duplicate' // duplicate
36+
duplicate: 'duplicate', // duplicate
37+
other: 'other' // other
3738
};
3839

3940
const Comment = sequelize.define(

db/models/Idea.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = function (sequelize, DataTypes) {
1616
spam: 'spam', // contains spam or is unrelated to topic
1717
hate: 'hate', // contains hate speech
1818
netiquette: 'netiquette', // infringes (n)etiquette
19-
duplicate: 'duplicate' // duplicate
19+
duplicate: 'duplicate', // duplicate
20+
other: 'other' // other
2021
};
2122

2223
const Idea = sequelize.define(

0 commit comments

Comments
 (0)