nocobase-plugin-dictionary-field 0.2.5 → 0.2.6
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/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Migration } from '@nocobase/database';
|
|
2
|
-
/**
|
|
3
|
-
* 迁移:为字典项添加树结构支持
|
|
4
|
-
*
|
|
5
|
-
* 添加字段:
|
|
6
|
-
* - parentId: 父项引用
|
|
7
|
-
* - isRoot: 是否为根项
|
|
8
|
-
* - depth: 树深度
|
|
9
|
-
* - sortOrder: 同级排序
|
|
10
|
-
*
|
|
11
|
-
* 添加关系:
|
|
12
|
-
* - parent: belongsTo 自引用
|
|
13
|
-
* - children: hasMany 自引用
|
|
14
|
-
*
|
|
15
|
-
* 添加索引用于性能优化
|
|
16
|
-
*/
|
|
17
|
-
export declare class AddTreeStructureMigration extends Migration {
|
|
18
|
-
up(): Promise<void>;
|
|
19
|
-
down(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export default AddTreeStructureMigration;
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var add_tree_structure_exports = {};
|
|
28
|
-
__export(add_tree_structure_exports, {
|
|
29
|
-
AddTreeStructureMigration: () => AddTreeStructureMigration,
|
|
30
|
-
default: () => add_tree_structure_default
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(add_tree_structure_exports);
|
|
33
|
-
var import_database = require("@nocobase/database");
|
|
34
|
-
var import_sequelize = require("sequelize");
|
|
35
|
-
class AddTreeStructureMigration extends import_database.Migration {
|
|
36
|
-
async up() {
|
|
37
|
-
const { db } = this.context;
|
|
38
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
39
|
-
const tableName = "rb_data_dictionary_items";
|
|
40
|
-
try {
|
|
41
|
-
const tableExists = await queryInterface.tableExists(tableName);
|
|
42
|
-
if (!tableExists) {
|
|
43
|
-
console.log(`\u8868 ${tableName} \u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u8FC1\u79FB`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
console.log("\u6DFB\u52A0\u6811\u7ED3\u6784\u5B57\u6BB5...");
|
|
47
|
-
try {
|
|
48
|
-
await queryInterface.addColumn(tableName, "parent_id", {
|
|
49
|
-
type: import_sequelize.DataTypes.INTEGER,
|
|
50
|
-
allowNull: true,
|
|
51
|
-
defaultValue: null,
|
|
52
|
-
comment: "\u7236\u9879ID\uFF0C\u7528\u4E8E\u6784\u5EFA\u6811\u7ED3\u6784"
|
|
53
|
-
});
|
|
54
|
-
console.log("\u2713 \u6DFB\u52A0 parent_id \u5217");
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
57
|
-
console.log("parent_id \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
58
|
-
} else {
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
await queryInterface.addColumn(tableName, "is_root", {
|
|
64
|
-
type: import_sequelize.DataTypes.BOOLEAN,
|
|
65
|
-
allowNull: false,
|
|
66
|
-
defaultValue: true,
|
|
67
|
-
comment: "\u662F\u5426\u4E3A\u6839\u9879"
|
|
68
|
-
});
|
|
69
|
-
console.log("\u2713 \u6DFB\u52A0 is_root \u5217");
|
|
70
|
-
} catch (error) {
|
|
71
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
72
|
-
console.log("is_root \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
73
|
-
} else {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
await queryInterface.addColumn(tableName, "depth", {
|
|
79
|
-
type: import_sequelize.DataTypes.INTEGER,
|
|
80
|
-
allowNull: false,
|
|
81
|
-
defaultValue: 0,
|
|
82
|
-
comment: "\u6811\u4E2D\u7684\u6DF1\u5EA6\u7EA7\u522B"
|
|
83
|
-
});
|
|
84
|
-
console.log("\u2713 \u6DFB\u52A0 depth \u5217");
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
87
|
-
console.log("depth \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
88
|
-
} else {
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
await queryInterface.addColumn(tableName, "sort_order", {
|
|
94
|
-
type: import_sequelize.DataTypes.INTEGER,
|
|
95
|
-
allowNull: false,
|
|
96
|
-
defaultValue: 0,
|
|
97
|
-
comment: "\u540C\u7EA7\u9879\u4E2D\u7684\u6392\u5E8F"
|
|
98
|
-
});
|
|
99
|
-
console.log("\u2713 \u6DFB\u52A0 sort_order \u5217");
|
|
100
|
-
} catch (error) {
|
|
101
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
102
|
-
console.log("sort_order \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
103
|
-
} else {
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
console.log("\u6DFB\u52A0\u5916\u952E\u7EA6\u675F...");
|
|
108
|
-
try {
|
|
109
|
-
await queryInterface.addConstraint(tableName, {
|
|
110
|
-
fields: ["parent_id"],
|
|
111
|
-
type: "foreign key",
|
|
112
|
-
name: "fk_parent_id",
|
|
113
|
-
references: {
|
|
114
|
-
table: tableName,
|
|
115
|
-
field: "id"
|
|
116
|
-
},
|
|
117
|
-
onDelete: "SET NULL",
|
|
118
|
-
onUpdate: "CASCADE"
|
|
119
|
-
});
|
|
120
|
-
console.log("\u2713 \u6DFB\u52A0\u5916\u952E\u7EA6\u675F fk_parent_id");
|
|
121
|
-
} catch (error) {
|
|
122
|
-
if (error.message.includes("already exists") || error.message.includes("Duplicate key") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
123
|
-
console.log("\u5916\u952E\u7EA6\u675F\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
124
|
-
} else {
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
console.log("\u6DFB\u52A0\u68C0\u67E5\u7EA6\u675F...");
|
|
129
|
-
try {
|
|
130
|
-
const dialect = db.sequelize.getDialect();
|
|
131
|
-
if (dialect === "mysql") {
|
|
132
|
-
await queryInterface.sequelize.query(
|
|
133
|
-
`ALTER TABLE ${tableName} ADD CONSTRAINT check_no_self_ref CHECK (parent_id IS NULL OR parent_id != id)`
|
|
134
|
-
);
|
|
135
|
-
} else if (dialect === "postgres") {
|
|
136
|
-
await queryInterface.sequelize.query(
|
|
137
|
-
`ALTER TABLE ${tableName} ADD CONSTRAINT check_no_self_ref CHECK (parent_id IS NULL OR parent_id != id)`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
console.log("\u2713 \u6DFB\u52A0\u68C0\u67E5\u7EA6\u675F check_no_self_ref");
|
|
141
|
-
} catch (error) {
|
|
142
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
143
|
-
console.log("\u68C0\u67E5\u7EA6\u675F\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
144
|
-
} else {
|
|
145
|
-
console.log("\u68C0\u67E5\u7EA6\u675F\u6DFB\u52A0\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u652F\u6301\uFF09\uFF0C\u7EE7\u7EED");
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
console.log("\u6DFB\u52A0\u7D22\u5F15...");
|
|
149
|
-
try {
|
|
150
|
-
await queryInterface.addIndex(tableName, {
|
|
151
|
-
fields: ["parent_id", "sort_order"],
|
|
152
|
-
name: "idx_parent_sort"
|
|
153
|
-
});
|
|
154
|
-
console.log("\u2713 \u6DFB\u52A0\u7D22\u5F15 idx_parent_sort");
|
|
155
|
-
} catch (error) {
|
|
156
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
157
|
-
console.log("\u7D22\u5F15 idx_parent_sort \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
158
|
-
} else {
|
|
159
|
-
throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
try {
|
|
163
|
-
await queryInterface.addIndex(tableName, {
|
|
164
|
-
fields: ["dictionary_type_id", "parent_id", "is_root"],
|
|
165
|
-
name: "idx_type_parent_root"
|
|
166
|
-
});
|
|
167
|
-
console.log("\u2713 \u6DFB\u52A0\u7D22\u5F15 idx_type_parent_root");
|
|
168
|
-
} catch (error) {
|
|
169
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
170
|
-
console.log("\u7D22\u5F15 idx_type_parent_root \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
171
|
-
} else {
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
await queryInterface.addIndex(tableName, {
|
|
177
|
-
fields: ["parent_id"],
|
|
178
|
-
name: "idx_parent_id"
|
|
179
|
-
});
|
|
180
|
-
console.log("\u2713 \u6DFB\u52A0\u7D22\u5F15 idx_parent_id");
|
|
181
|
-
} catch (error) {
|
|
182
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
183
|
-
console.log("\u7D22\u5F15 idx_parent_id \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
184
|
-
} else {
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
await queryInterface.addIndex(tableName, {
|
|
190
|
-
fields: ["depth"],
|
|
191
|
-
name: "idx_depth"
|
|
192
|
-
});
|
|
193
|
-
console.log("\u2713 \u6DFB\u52A0\u7D22\u5F15 idx_depth");
|
|
194
|
-
} catch (error) {
|
|
195
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
196
|
-
console.log("\u7D22\u5F15 idx_depth \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
197
|
-
} else {
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
console.log("\u66F4\u65B0\u73B0\u6709\u6570\u636E...");
|
|
202
|
-
try {
|
|
203
|
-
await queryInterface.sequelize.query(
|
|
204
|
-
`UPDATE ${tableName} SET parent_id = NULL, is_root = true, depth = 0 WHERE parent_id IS NULL AND is_root = false`
|
|
205
|
-
);
|
|
206
|
-
console.log("\u2713 \u66F4\u65B0\u73B0\u6709\u6570\u636E\uFF1A\u8BBE\u7F6E\u6839\u9879\u6807\u8BB0");
|
|
207
|
-
} catch (error) {
|
|
208
|
-
console.log("\u66F4\u65B0\u73B0\u6709\u6570\u636E\u5931\u8D25\u6216\u65E0\u9700\u66F4\u65B0:", error.message);
|
|
209
|
-
}
|
|
210
|
-
console.log("\u2705 \u6811\u7ED3\u6784\u8FC1\u79FB\u5B8C\u6210");
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error("\u274C \u6811\u7ED3\u6784\u8FC1\u79FB\u5931\u8D25:", error);
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
async down() {
|
|
217
|
-
const { db } = this.context;
|
|
218
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
219
|
-
const tableName = "rb_data_dictionary_items";
|
|
220
|
-
try {
|
|
221
|
-
console.log("\u56DE\u6EDA\u6811\u7ED3\u6784\u8FC1\u79FB...");
|
|
222
|
-
const tableExists = await queryInterface.tableExists(tableName);
|
|
223
|
-
if (!tableExists) {
|
|
224
|
-
console.log(`\u8868 ${tableName} \u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u56DE\u6EDA`);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
await queryInterface.removeConstraint(tableName, "fk_parent_id");
|
|
229
|
-
console.log("\u2713 \u79FB\u9664\u5916\u952E fk_parent_id");
|
|
230
|
-
} catch (error) {
|
|
231
|
-
console.log("\u79FB\u9664\u5916\u952E\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
232
|
-
}
|
|
233
|
-
try {
|
|
234
|
-
await queryInterface.removeConstraint(tableName, "check_no_self_ref");
|
|
235
|
-
console.log("\u2713 \u79FB\u9664\u68C0\u67E5\u7EA6\u675F check_no_self_ref");
|
|
236
|
-
} catch (error) {
|
|
237
|
-
console.log("\u79FB\u9664\u68C0\u67E5\u7EA6\u675F\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
238
|
-
}
|
|
239
|
-
try {
|
|
240
|
-
await queryInterface.removeIndex(tableName, "idx_parent_sort");
|
|
241
|
-
console.log("\u2713 \u79FB\u9664\u7D22\u5F15 idx_parent_sort");
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.log("\u79FB\u9664\u7D22\u5F15\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
244
|
-
}
|
|
245
|
-
try {
|
|
246
|
-
await queryInterface.removeIndex(tableName, "idx_type_parent_root");
|
|
247
|
-
console.log("\u2713 \u79FB\u9664\u7D22\u5F15 idx_type_parent_root");
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.log("\u79FB\u9664\u7D22\u5F15\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
await queryInterface.removeIndex(tableName, "idx_parent_id");
|
|
253
|
-
console.log("\u2713 \u79FB\u9664\u7D22\u5F15 idx_parent_id");
|
|
254
|
-
} catch (error) {
|
|
255
|
-
console.log("\u79FB\u9664\u7D22\u5F15\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
256
|
-
}
|
|
257
|
-
try {
|
|
258
|
-
await queryInterface.removeIndex(tableName, "idx_depth");
|
|
259
|
-
console.log("\u2713 \u79FB\u9664\u7D22\u5F15 idx_depth");
|
|
260
|
-
} catch (error) {
|
|
261
|
-
console.log("\u79FB\u9664\u7D22\u5F15\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
262
|
-
}
|
|
263
|
-
try {
|
|
264
|
-
await queryInterface.removeColumn(tableName, "parent_id");
|
|
265
|
-
console.log("\u2713 \u79FB\u9664\u5217 parent_id");
|
|
266
|
-
} catch (error) {
|
|
267
|
-
console.log("\u79FB\u9664\u5217\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
268
|
-
}
|
|
269
|
-
try {
|
|
270
|
-
await queryInterface.removeColumn(tableName, "is_root");
|
|
271
|
-
console.log("\u2713 \u79FB\u9664\u5217 is_root");
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.log("\u79FB\u9664\u5217\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
274
|
-
}
|
|
275
|
-
try {
|
|
276
|
-
await queryInterface.removeColumn(tableName, "depth");
|
|
277
|
-
console.log("\u2713 \u79FB\u9664\u5217 depth");
|
|
278
|
-
} catch (error) {
|
|
279
|
-
console.log("\u79FB\u9664\u5217\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
280
|
-
}
|
|
281
|
-
try {
|
|
282
|
-
await queryInterface.removeColumn(tableName, "sort_order");
|
|
283
|
-
console.log("\u2713 \u79FB\u9664\u5217 sort_order");
|
|
284
|
-
} catch (error) {
|
|
285
|
-
console.log("\u79FB\u9664\u5217\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
286
|
-
}
|
|
287
|
-
console.log("\u2705 \u6811\u7ED3\u6784\u8FC1\u79FB\u56DE\u6EDA\u5B8C\u6210");
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.error("\u274C \u6811\u7ED3\u6784\u8FC1\u79FB\u56DE\u6EDA\u5931\u8D25:", error);
|
|
290
|
-
throw error;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
var add_tree_structure_default = AddTreeStructureMigration;
|
|
295
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
296
|
-
0 && (module.exports = {
|
|
297
|
-
AddTreeStructureMigration
|
|
298
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Migration } from '@nocobase/database';
|
|
2
|
-
/**
|
|
3
|
-
* 迁移:为字典类型添加 isTree 字段
|
|
4
|
-
*
|
|
5
|
-
* 添加字段:
|
|
6
|
-
* - isTree: 是否为树形字典(布尔值,默认为 false)
|
|
7
|
-
*/
|
|
8
|
-
export declare class AddIsTreeFieldMigration extends Migration {
|
|
9
|
-
up(): Promise<void>;
|
|
10
|
-
down(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export default AddIsTreeFieldMigration;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __export = (target, all) => {
|
|
15
|
-
for (var name in all)
|
|
16
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from))
|
|
21
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
-
}
|
|
24
|
-
return to;
|
|
25
|
-
};
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
var add_is_tree_field_exports = {};
|
|
28
|
-
__export(add_is_tree_field_exports, {
|
|
29
|
-
AddIsTreeFieldMigration: () => AddIsTreeFieldMigration,
|
|
30
|
-
default: () => add_is_tree_field_default
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(add_is_tree_field_exports);
|
|
33
|
-
var import_database = require("@nocobase/database");
|
|
34
|
-
var import_sequelize = require("sequelize");
|
|
35
|
-
class AddIsTreeFieldMigration extends import_database.Migration {
|
|
36
|
-
async up() {
|
|
37
|
-
const { db } = this.context;
|
|
38
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
39
|
-
const tableName = "rb_data_dictionary_types";
|
|
40
|
-
try {
|
|
41
|
-
const tableExists = await queryInterface.tableExists(tableName);
|
|
42
|
-
if (!tableExists) {
|
|
43
|
-
console.log(`\u8868 ${tableName} \u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u8FC1\u79FB`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const columns = await queryInterface.describeTable(tableName);
|
|
47
|
-
if (columns.is_tree) {
|
|
48
|
-
console.log("is_tree \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
console.log("\u6DFB\u52A0 is_tree \u5217...");
|
|
52
|
-
try {
|
|
53
|
-
await queryInterface.addColumn(tableName, "is_tree", {
|
|
54
|
-
type: import_sequelize.DataTypes.BOOLEAN,
|
|
55
|
-
allowNull: false,
|
|
56
|
-
defaultValue: false,
|
|
57
|
-
comment: "\u662F\u5426\u4E3A\u6811\u5F62\u5B57\u5178"
|
|
58
|
-
});
|
|
59
|
-
console.log("\u2713 \u6DFB\u52A0 is_tree \u5217\u6210\u529F");
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (error.message.includes("already exists") || error.message.includes("\u5DF2\u5B58\u5728")) {
|
|
62
|
-
console.log("is_tree \u5217\u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");
|
|
63
|
-
} else {
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
console.log("\u2705 isTree \u5B57\u6BB5\u6DFB\u52A0\u8FC1\u79FB\u5B8C\u6210");
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("\u274C isTree \u5B57\u6BB5\u6DFB\u52A0\u8FC1\u79FB\u5931\u8D25:", error);
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
async down() {
|
|
74
|
-
const { db } = this.context;
|
|
75
|
-
const queryInterface = db.sequelize.getQueryInterface();
|
|
76
|
-
const tableName = "rb_data_dictionary_types";
|
|
77
|
-
try {
|
|
78
|
-
console.log("\u56DE\u6EDA isTree \u5B57\u6BB5\u8FC1\u79FB...");
|
|
79
|
-
const tableExists = await queryInterface.tableExists(tableName);
|
|
80
|
-
if (!tableExists) {
|
|
81
|
-
console.log(`\u8868 ${tableName} \u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u56DE\u6EDA`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
await queryInterface.removeColumn(tableName, "is_tree");
|
|
86
|
-
console.log("\u2713 \u79FB\u9664\u5217 is_tree");
|
|
87
|
-
} catch (error) {
|
|
88
|
-
console.log("\u79FB\u9664\u5217\u5931\u8D25\uFF08\u53EF\u80FD\u4E0D\u5B58\u5728\uFF09:", error.message);
|
|
89
|
-
}
|
|
90
|
-
console.log("\u2705 isTree \u5B57\u6BB5\u8FC1\u79FB\u56DE\u6EDA\u5B8C\u6210");
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error("\u274C isTree \u5B57\u6BB5\u8FC1\u79FB\u56DE\u6EDA\u5931\u8D25:", error);
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
var add_is_tree_field_default = AddIsTreeFieldMigration;
|
|
98
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
-
0 && (module.exports = {
|
|
100
|
-
AddIsTreeFieldMigration
|
|
101
|
-
});
|