@kipicore/dbcore 1.1.729 → 1.1.730
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/db/psql/migrations/20260819160514-change_announcements_user_types_enum_to_string.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = {
|
|
3
|
+
up: async (queryInterface, Sequelize) => {
|
|
4
|
+
const table = await queryInterface
|
|
5
|
+
.describeTable('announcementes')
|
|
6
|
+
.catch(() => null);
|
|
7
|
+
if (!table)
|
|
8
|
+
return;
|
|
9
|
+
// 1. Update schedule_type / scheduleType (scalar STRING)
|
|
10
|
+
const scheduleTypeCol = table.schedule_type ? 'schedule_type' : (table.scheduleType ? 'scheduleType' : null);
|
|
11
|
+
if (scheduleTypeCol) {
|
|
12
|
+
try {
|
|
13
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${scheduleTypeCol}" DROP DEFAULT;`);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Ignore if default does not exist
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${scheduleTypeCol}" TYPE VARCHAR(255) USING "${scheduleTypeCol}"::varchar;`);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Ignore if alter type fails
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
await queryInterface.changeColumn('announcementes', scheduleTypeCol, {
|
|
26
|
+
type: Sequelize.STRING,
|
|
27
|
+
allowNull: false,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Ignore if change column fails
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// 2. Update userTypes / user_types (ARRAY of STRING)
|
|
35
|
+
const userTypesCol = table.userTypes ? 'userTypes' : (table.user_types ? 'user_types' : null);
|
|
36
|
+
if (userTypesCol) {
|
|
37
|
+
try {
|
|
38
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${userTypesCol}" DROP DEFAULT;`);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Ignore if default does not exist
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${userTypesCol}" TYPE VARCHAR(255)[] USING "${userTypesCol}"::text[];`);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
try {
|
|
48
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${userTypesCol}" TYPE VARCHAR(255)[] USING ARRAY["${userTypesCol}"]::text[];`);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Ignore fallback failure
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
await queryInterface.changeColumn('announcementes', userTypesCol, {
|
|
56
|
+
type: Sequelize.ARRAY(Sequelize.STRING),
|
|
57
|
+
allowNull: true,
|
|
58
|
+
defaultValue: [],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Ignore change column failure
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// 3. Update status (scalar STRING)
|
|
66
|
+
if (table.status) {
|
|
67
|
+
try {
|
|
68
|
+
await queryInterface.sequelize.query('ALTER TABLE announcementes ALTER COLUMN "status" DROP DEFAULT;');
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Ignore if default does not exist
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await queryInterface.sequelize.query('ALTER TABLE announcementes ALTER COLUMN "status" TYPE VARCHAR(255) USING "status"::varchar;');
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// Ignore if alter type fails
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
await queryInterface.sequelize.query("ALTER TABLE announcementes ALTER COLUMN \"status\" SET DEFAULT 'PENDING';");
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// Ignore if setting default fails
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
await queryInterface.changeColumn('announcementes', 'status', {
|
|
87
|
+
type: Sequelize.STRING,
|
|
88
|
+
allowNull: false,
|
|
89
|
+
defaultValue: 'PENDING',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Ignore if change column fails
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Drop enum types if they exist in PostgreSQL
|
|
97
|
+
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_announcementes_schedule_type" CASCADE;').catch(() => { });
|
|
98
|
+
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_announcementes_scheduleType" CASCADE;').catch(() => { });
|
|
99
|
+
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_announcementes_userTypes" CASCADE;').catch(() => { });
|
|
100
|
+
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_announcementes_user_types" CASCADE;').catch(() => { });
|
|
101
|
+
await queryInterface.sequelize.query('DROP TYPE IF EXISTS "enum_announcementes_status" CASCADE;').catch(() => { });
|
|
102
|
+
},
|
|
103
|
+
down: async (queryInterface, Sequelize) => {
|
|
104
|
+
const table = await queryInterface
|
|
105
|
+
.describeTable('announcementes')
|
|
106
|
+
.catch(() => null);
|
|
107
|
+
if (!table)
|
|
108
|
+
return;
|
|
109
|
+
const scheduleTypeCol = table.schedule_type ? 'schedule_type' : (table.scheduleType ? 'scheduleType' : null);
|
|
110
|
+
if (scheduleTypeCol) {
|
|
111
|
+
try {
|
|
112
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${scheduleTypeCol}" TYPE "enum_announcementes_schedule_type" USING "${scheduleTypeCol}"::text::"enum_announcementes_schedule_type";`);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Ignore if alter fails
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await queryInterface.changeColumn('announcementes', scheduleTypeCol, {
|
|
119
|
+
type: Sequelize.ENUM('INSTANT', 'SCHEDULE'),
|
|
120
|
+
allowNull: false,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Ignore if change column fails
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const userTypesCol = table.userTypes ? 'userTypes' : (table.user_types ? 'user_types' : null);
|
|
128
|
+
if (userTypesCol) {
|
|
129
|
+
try {
|
|
130
|
+
await queryInterface.sequelize.query(`ALTER TABLE announcementes ALTER COLUMN "${userTypesCol}" TYPE "enum_announcementes_user_types"[] USING "${userTypesCol}"::text[]::"enum_announcementes_user_types"[];`);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Ignore if alter fails
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
await queryInterface.changeColumn('announcementes', userTypesCol, {
|
|
137
|
+
type: Sequelize.ARRAY(Sequelize.ENUM('MASTER_ADMIN', 'ADMIN', 'INSTITUTE_MASTER_ADMIN', 'INSTITUTE_ADMIN', 'TEACHER', 'STUDENT', 'PARENTS', 'DRIVER')),
|
|
138
|
+
allowNull: true,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Ignore if change column fails
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (table.status) {
|
|
146
|
+
try {
|
|
147
|
+
await queryInterface.sequelize.query('ALTER TABLE announcementes ALTER COLUMN "status" TYPE "enum_announcementes_status" USING "status"::text::"enum_announcementes_status";');
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Ignore if alter fails
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
await queryInterface.changeColumn('announcementes', 'status', {
|
|
154
|
+
type: Sequelize.ENUM('PENDING', 'PROCESSING', 'CREATED'),
|
|
155
|
+
allowNull: false,
|
|
156
|
+
defaultValue: 'PENDING',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Ignore if change column fails
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
package/package.json
CHANGED