@tachybase/module-collection 0.23.8

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.
Files changed (90) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/LICENSE +201 -0
  3. package/README.md +9 -0
  4. package/README.zh-CN.md +9 -0
  5. package/client.d.ts +2 -0
  6. package/client.js +1 -0
  7. package/dist/client/index.d.ts +5 -0
  8. package/dist/client/index.js +1 -0
  9. package/dist/externalVersion.js +14 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +39 -0
  12. package/dist/server/actions/collectionImportExportMeta.d.ts +2 -0
  13. package/dist/server/actions/collectionImportExportMeta.js +226 -0
  14. package/dist/server/collections/collectionCategories.d.ts +3 -0
  15. package/dist/server/collections/collectionCategories.js +52 -0
  16. package/dist/server/collections/collections.d.ts +3 -0
  17. package/dist/server/collections/collections.js +92 -0
  18. package/dist/server/collections/fields.d.ts +3 -0
  19. package/dist/server/collections/fields.js +94 -0
  20. package/dist/server/hooks/afterCreateForForeignKeyField.d.ts +2 -0
  21. package/dist/server/hooks/afterCreateForForeignKeyField.js +195 -0
  22. package/dist/server/hooks/afterCreateForReverseField.d.ts +4 -0
  23. package/dist/server/hooks/afterCreateForReverseField.js +37 -0
  24. package/dist/server/hooks/afterDestroyForForeignKeyField.d.ts +2 -0
  25. package/dist/server/hooks/afterDestroyForForeignKeyField.js +89 -0
  26. package/dist/server/hooks/beforeCreateForChildrenCollection.d.ts +5 -0
  27. package/dist/server/hooks/beforeCreateForChildrenCollection.js +58 -0
  28. package/dist/server/hooks/beforeCreateForReverseField.d.ts +4 -0
  29. package/dist/server/hooks/beforeCreateForReverseField.js +64 -0
  30. package/dist/server/hooks/beforeCreateForValidateField.d.ts +4 -0
  31. package/dist/server/hooks/beforeCreateForValidateField.js +48 -0
  32. package/dist/server/hooks/beforeCreateForViewCollection.d.ts +5 -0
  33. package/dist/server/hooks/beforeCreateForViewCollection.js +30 -0
  34. package/dist/server/hooks/beforeDestroyForeignKey.d.ts +2 -0
  35. package/dist/server/hooks/beforeDestroyForeignKey.js +66 -0
  36. package/dist/server/hooks/beforeInitOptions.d.ts +29 -0
  37. package/dist/server/hooks/beforeInitOptions.js +233 -0
  38. package/dist/server/hooks/index.d.ts +6 -0
  39. package/dist/server/hooks/index.js +31 -0
  40. package/dist/server/index.d.ts +4 -0
  41. package/dist/server/index.js +45 -0
  42. package/dist/server/migrations/20220613103214-alert-sub-table.d.ts +5 -0
  43. package/dist/server/migrations/20220613103214-alert-sub-table.js +40 -0
  44. package/dist/server/migrations/20220704225714-drop-foreign-keys.d.ts +5 -0
  45. package/dist/server/migrations/20220704225714-drop-foreign-keys.js +67 -0
  46. package/dist/server/migrations/20221101111110-update-foreign-fields.d.ts +5 -0
  47. package/dist/server/migrations/20221101111110-update-foreign-fields.js +64 -0
  48. package/dist/server/migrations/20221104151410-update-collections-hidden.d.ts +5 -0
  49. package/dist/server/migrations/20221104151410-update-collections-hidden.js +47 -0
  50. package/dist/server/migrations/20221121111110-update-fk-type.d.ts +5 -0
  51. package/dist/server/migrations/20221121111110-update-fk-type.js +144 -0
  52. package/dist/server/migrations/20221121111113-update-id-to-bigint.d.ts +5 -0
  53. package/dist/server/migrations/20221121111113-update-id-to-bigint.js +178 -0
  54. package/dist/server/migrations/20221221103220-timestamps.d.ts +5 -0
  55. package/dist/server/migrations/20221221103220-timestamps.js +45 -0
  56. package/dist/server/migrations/20230225111112-drop-ui-schema-relation.d.ts +5 -0
  57. package/dist/server/migrations/20230225111112-drop-ui-schema-relation.js +87 -0
  58. package/dist/server/migrations/20230509111114-alert-ui-schema.d.ts +5 -0
  59. package/dist/server/migrations/20230509111114-alert-ui-schema.js +77 -0
  60. package/dist/server/migrations/20230623145414-number-step.d.ts +5 -0
  61. package/dist/server/migrations/20230623145414-number-step.js +71 -0
  62. package/dist/server/migrations/20230704222935-tableoid.d.ts +5 -0
  63. package/dist/server/migrations/20230704222935-tableoid.js +73 -0
  64. package/dist/server/migrations/20230918024546-set-collection-schema.d.ts +5 -0
  65. package/dist/server/migrations/20230918024546-set-collection-schema.js +45 -0
  66. package/dist/server/migrations/20240220153103-install-main-datasource.d.ts +6 -0
  67. package/dist/server/migrations/20240220153103-install-main-datasource.js +41 -0
  68. package/dist/server/models/collection.d.ts +23 -0
  69. package/dist/server/models/collection.js +221 -0
  70. package/dist/server/models/field.d.ts +22 -0
  71. package/dist/server/models/field.js +188 -0
  72. package/dist/server/models/index.d.ts +2 -0
  73. package/dist/server/models/index.js +23 -0
  74. package/dist/server/repositories/collection-repository.d.ts +12 -0
  75. package/dist/server/repositories/collection-repository.js +135 -0
  76. package/dist/server/repositories/index.d.ts +1 -0
  77. package/dist/server/repositories/index.js +21 -0
  78. package/dist/server/resourcers/collections.d.ts +4 -0
  79. package/dist/server/resourcers/collections.js +93 -0
  80. package/dist/server/resourcers/sql.d.ts +10 -0
  81. package/dist/server/resourcers/sql.js +108 -0
  82. package/dist/server/resourcers/views.d.ts +9 -0
  83. package/dist/server/resourcers/views.js +98 -0
  84. package/dist/server/server.d.ts +11 -0
  85. package/dist/server/server.js +332 -0
  86. package/dist/swagger/index.d.ts +405 -0
  87. package/dist/swagger/index.js +431 -0
  88. package/package.json +34 -0
  89. package/server.d.ts +2 -0
  90. package/server.js +1 -0
@@ -0,0 +1,64 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var update_foreign_fields_exports = {};
19
+ __export(update_foreign_fields_exports, {
20
+ default: () => DropForeignKeysMigration
21
+ });
22
+ module.exports = __toCommonJS(update_foreign_fields_exports);
23
+ var import_server = require("@tachybase/server");
24
+ var import_afterCreateForForeignKeyField = require("../hooks/afterCreateForForeignKeyField");
25
+ class DropForeignKeysMigration extends import_server.Migration {
26
+ appVersion = "<0.8.0-alpha.9";
27
+ async up() {
28
+ const result = await this.app.version.satisfies("<0.8.0");
29
+ if (!result) {
30
+ return;
31
+ }
32
+ const transaction = await this.app.db.sequelize.transaction();
33
+ const callback = (0, import_afterCreateForForeignKeyField.afterCreateForForeignKeyField)(this.app.db);
34
+ try {
35
+ const fields = await this.app.db.getCollection("fields").repository.find({
36
+ filter: {
37
+ interface: {
38
+ $in: ["oho", "o2m", "obo", "m2o", "linkTo", "m2m"]
39
+ },
40
+ collectionName: {
41
+ $not: null
42
+ }
43
+ }
44
+ });
45
+ for (const field of fields) {
46
+ try {
47
+ await callback(field, {
48
+ transaction,
49
+ context: {}
50
+ });
51
+ } catch (error) {
52
+ if (error.message.includes("collection not found")) {
53
+ continue;
54
+ }
55
+ throw error;
56
+ }
57
+ }
58
+ await transaction.commit();
59
+ } catch (error) {
60
+ console.log(error);
61
+ await transaction.rollback();
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class UpdateCollectionsHiddenMigration extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var update_collections_hidden_exports = {};
19
+ __export(update_collections_hidden_exports, {
20
+ default: () => UpdateCollectionsHiddenMigration
21
+ });
22
+ module.exports = __toCommonJS(update_collections_hidden_exports);
23
+ var import_server = require("@tachybase/server");
24
+ class UpdateCollectionsHiddenMigration extends import_server.Migration {
25
+ appVersion = "<0.8.0-alpha.11";
26
+ async up() {
27
+ const result = await this.app.version.satisfies("<=0.8.0-alpha.9");
28
+ if (!result) {
29
+ return;
30
+ }
31
+ try {
32
+ await this.app.db.getRepository("collections").update({
33
+ filter: {
34
+ options: {
35
+ autoCreate: true,
36
+ isThrough: true
37
+ }
38
+ },
39
+ values: {
40
+ hidden: true
41
+ }
42
+ });
43
+ } catch (error) {
44
+ console.error(error);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class UpdateIdToBigIntMigrator extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,144 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var update_fk_type_exports = {};
19
+ __export(update_fk_type_exports, {
20
+ default: () => UpdateIdToBigIntMigrator
21
+ });
22
+ module.exports = __toCommonJS(update_fk_type_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var import_server = require("@tachybase/server");
25
+ class UpdateIdToBigIntMigrator extends import_server.Migration {
26
+ appVersion = "<0.8.1-alpha.2";
27
+ async up() {
28
+ const result = await this.app.version.satisfies("<0.9.0-alpha.1");
29
+ if (!result) {
30
+ return;
31
+ }
32
+ const db = this.app.db;
33
+ await db.getCollection("fields").repository.update({
34
+ filter: {
35
+ name: "id",
36
+ type: "integer"
37
+ },
38
+ values: {
39
+ type: "bigInt"
40
+ }
41
+ });
42
+ if (!db.inDialect("mysql", "mariadb", "postgres")) {
43
+ return;
44
+ }
45
+ const models = [];
46
+ const queryInterface = db.sequelize.getQueryInterface();
47
+ const queryGenerator = queryInterface.queryGenerator;
48
+ const updateToBigInt = async (model, fieldName) => {
49
+ let sql;
50
+ const tableName = model.tableName;
51
+ if (model.rawAttributes[fieldName].type instanceof import_database.DataTypes.INTEGER) {
52
+ if (db.inDialect("postgres")) {
53
+ sql = `ALTER TABLE "${tableName}" ALTER COLUMN "${fieldName}" SET DATA TYPE BIGINT;`;
54
+ } else if (db.inDialect("mysql", "mariadb")) {
55
+ const dataTypeOrOptions = model.rawAttributes[fieldName];
56
+ const attributeName = fieldName;
57
+ const query = queryGenerator.attributesToSQL(
58
+ {
59
+ [attributeName]: queryInterface.normalizeAttribute({
60
+ ...dataTypeOrOptions,
61
+ type: import_database.DataTypes.BIGINT
62
+ })
63
+ },
64
+ {
65
+ context: "changeColumn",
66
+ table: tableName
67
+ }
68
+ );
69
+ sql = queryGenerator.changeColumnQuery(tableName, query);
70
+ sql = sql.replace(" PRIMARY KEY;", " ;");
71
+ }
72
+ try {
73
+ await this.sequelize.query(sql, {});
74
+ } catch (err) {
75
+ if (err.message.includes("does not exist")) {
76
+ return;
77
+ }
78
+ throw err;
79
+ }
80
+ this.app.logger.info(`updated ${tableName}.${fieldName} to BIGINT`, { tableName, fieldName });
81
+ }
82
+ };
83
+ this.app.db.sequelize.modelManager.forEachModel((model) => {
84
+ models.push(model);
85
+ });
86
+ for (const model of models) {
87
+ try {
88
+ const primaryKeyField = model.tableAttributes[model.primaryKeyField];
89
+ const collection = db.modelCollection.get(model);
90
+ if (!collection) {
91
+ continue;
92
+ }
93
+ if (primaryKeyField && primaryKeyField.primaryKey) {
94
+ await updateToBigInt(model, model.primaryKeyField);
95
+ }
96
+ if (model.tableAttributes["sort"] && model.tableAttributes["sort"].type instanceof import_database.DataTypes.INTEGER) {
97
+ await updateToBigInt(model, "sort");
98
+ }
99
+ const associations = model.associations;
100
+ for (const associationName of Object.keys(associations)) {
101
+ const association = associations[associationName];
102
+ const type = association.associationType;
103
+ let foreignModel;
104
+ let fieldName;
105
+ if (type === "BelongsTo") {
106
+ foreignModel = association.source;
107
+ fieldName = association.foreignKey;
108
+ }
109
+ if (type === "HasMany") {
110
+ foreignModel = association.target;
111
+ fieldName = association.foreignKey;
112
+ }
113
+ if (type === "HasOne") {
114
+ foreignModel = association.target;
115
+ fieldName = association.foreignKey;
116
+ }
117
+ if (foreignModel && fieldName) {
118
+ const cf = await db.getRepository("collections.fields", foreignModel.name).findOne({
119
+ filterByTk: fieldName
120
+ });
121
+ if (cf) {
122
+ cf.interface = "integer";
123
+ cf.type = "bigInt";
124
+ await cf.save();
125
+ }
126
+ await updateToBigInt(foreignModel, fieldName);
127
+ }
128
+ if (type === "BelongsToMany") {
129
+ const throughModel = association.through.model;
130
+ const otherKey = association.otherKey;
131
+ const foreignKey = association.foreignKey;
132
+ await updateToBigInt(throughModel, otherKey);
133
+ await updateToBigInt(throughModel, foreignKey);
134
+ }
135
+ }
136
+ } catch (error) {
137
+ if (error.message.includes("cannot alter inherited column")) {
138
+ continue;
139
+ }
140
+ throw error;
141
+ }
142
+ }
143
+ }
144
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class UpdateIdToBigIntMigrator extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,178 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var update_id_to_bigint_exports = {};
19
+ __export(update_id_to_bigint_exports, {
20
+ default: () => UpdateIdToBigIntMigrator
21
+ });
22
+ module.exports = __toCommonJS(update_id_to_bigint_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var import_server = require("@tachybase/server");
25
+ class UpdateIdToBigIntMigrator extends import_server.Migration {
26
+ appVersion = "<0.8.1-alpha.2";
27
+ async up() {
28
+ const result = await this.app.version.satisfies("<0.9.0-alpha.1");
29
+ if (!result) {
30
+ return;
31
+ }
32
+ const db = this.app.db;
33
+ await db.getCollection("fields").repository.update({
34
+ filter: {
35
+ $or: [
36
+ {
37
+ name: "id",
38
+ type: "integer"
39
+ }
40
+ ]
41
+ },
42
+ values: {
43
+ type: "bigInt"
44
+ }
45
+ });
46
+ if (!db.inDialect("mysql", "mariadb", "postgres")) {
47
+ return;
48
+ }
49
+ const models = [];
50
+ const queryInterface = db.sequelize.getQueryInterface();
51
+ const queryGenerator = queryInterface.queryGenerator;
52
+ const updateToBigInt = async (model, fieldName) => {
53
+ const columnName = model.rawAttributes[fieldName].field;
54
+ let sql;
55
+ const tableName = model.tableName;
56
+ const addSchemaTableName = db.utils.addSchema(tableName);
57
+ const quoteTableName = db.utils.quoteTable(addSchemaTableName);
58
+ const collection = db.modelCollection.get(model);
59
+ const fieldRecord = await db.getCollection("fields").repository.findOne({
60
+ filter: {
61
+ collectionName: collection.name,
62
+ name: fieldName,
63
+ type: "integer"
64
+ }
65
+ });
66
+ if (fieldRecord) {
67
+ fieldRecord.set("type", "bigInt");
68
+ await fieldRecord.save();
69
+ }
70
+ if (model.rawAttributes[fieldName].type instanceof import_database.DataTypes.INTEGER) {
71
+ if (db.inDialect("postgres")) {
72
+ sql = `ALTER TABLE ${quoteTableName} ALTER COLUMN "${columnName}" SET DATA TYPE BIGINT;`;
73
+ } else if (db.inDialect("mysql", "mariadb")) {
74
+ const dataTypeOrOptions = model.rawAttributes[fieldName];
75
+ const attributeName = fieldName;
76
+ const query = queryGenerator.attributesToSQL(
77
+ {
78
+ [attributeName]: queryInterface.normalizeAttribute({
79
+ ...dataTypeOrOptions,
80
+ type: import_database.DataTypes.BIGINT
81
+ })
82
+ },
83
+ {
84
+ context: "changeColumn",
85
+ table: tableName
86
+ }
87
+ );
88
+ sql = queryGenerator.changeColumnQuery(addSchemaTableName, query);
89
+ sql = sql.replace(" PRIMARY KEY;", " ;");
90
+ }
91
+ try {
92
+ await this.sequelize.query(sql, {});
93
+ } catch (err) {
94
+ if (err.message.includes("does not exist") || err.message.includes("cannot alter inherited column")) {
95
+ return;
96
+ }
97
+ throw err;
98
+ }
99
+ if (db.inDialect("postgres")) {
100
+ const sequenceQuery = `SELECT pg_get_serial_sequence('${quoteTableName}', '${columnName}');`;
101
+ const [result2] = await this.sequelize.query(sequenceQuery, {});
102
+ const sequenceName = result2[0]["pg_get_serial_sequence"];
103
+ if (sequenceName) {
104
+ await this.sequelize.query(`ALTER SEQUENCE ${sequenceName} AS BIGINT;`, {});
105
+ }
106
+ }
107
+ this.app.logger.info(`updated ${tableName}.${fieldName} to BIGINT`, { tableName, fieldName });
108
+ }
109
+ };
110
+ const singleForeignFields = await db.getCollection("fields").repository.find({
111
+ filter: {
112
+ options: {
113
+ isForeignKey: true
114
+ },
115
+ type: "integer"
116
+ }
117
+ });
118
+ for (const field of singleForeignFields) {
119
+ const collection = db.getCollection(field.get("collectionName"));
120
+ if (!collection) {
121
+ console.log("collection not found", field.get("collectionName"));
122
+ }
123
+ await updateToBigInt(collection.model, field.get("name"));
124
+ }
125
+ this.app.db.sequelize.modelManager.forEachModel((model) => {
126
+ models.push(model);
127
+ });
128
+ for (const model of models) {
129
+ try {
130
+ const primaryKeyField = model.tableAttributes[model.primaryKeyField];
131
+ const collection = db.modelCollection.get(model);
132
+ if (!collection) {
133
+ continue;
134
+ }
135
+ if (primaryKeyField && primaryKeyField.primaryKey) {
136
+ await updateToBigInt(model, model.primaryKeyField);
137
+ }
138
+ if (model.tableAttributes["sort"] && model.tableAttributes["sort"].type instanceof import_database.DataTypes.INTEGER) {
139
+ await updateToBigInt(model, "sort");
140
+ }
141
+ const associations = model.associations;
142
+ for (const associationName of Object.keys(associations)) {
143
+ const association = associations[associationName];
144
+ const type = association.associationType;
145
+ let foreignModel;
146
+ let fieldName;
147
+ if (type === "BelongsTo") {
148
+ foreignModel = association.source;
149
+ fieldName = association.foreignKey;
150
+ }
151
+ if (type === "HasMany") {
152
+ foreignModel = association.target;
153
+ fieldName = association.foreignKey;
154
+ }
155
+ if (type === "HasOne") {
156
+ foreignModel = association.target;
157
+ fieldName = association.foreignKey;
158
+ }
159
+ if (foreignModel && fieldName) {
160
+ await updateToBigInt(foreignModel, fieldName);
161
+ }
162
+ if (type === "BelongsToMany") {
163
+ const throughModel = association.through.model;
164
+ const otherKey = association.otherKey;
165
+ const foreignKey = association.foreignKey;
166
+ await updateToBigInt(throughModel, otherKey);
167
+ await updateToBigInt(throughModel, foreignKey);
168
+ }
169
+ }
170
+ } catch (error) {
171
+ if (error.message.includes("cannot alter inherited column")) {
172
+ continue;
173
+ }
174
+ throw error;
175
+ }
176
+ }
177
+ }
178
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var timestamps_exports = {};
19
+ __export(timestamps_exports, {
20
+ default: () => timestamps_default
21
+ });
22
+ module.exports = __toCommonJS(timestamps_exports);
23
+ var import_server = require("@tachybase/server");
24
+ class timestamps_default extends import_server.Migration {
25
+ appVersion = "<0.8.1-alpha.2";
26
+ async up() {
27
+ const result = await this.app.version.satisfies("<=0.8.0-alpha.14");
28
+ if (!result) {
29
+ return;
30
+ }
31
+ try {
32
+ const collections = await this.app.db.getRepository("collections").find();
33
+ console.log("migrating...");
34
+ for (const collection of collections) {
35
+ if (collection.get("autoCreate") && collection.get("isThrough")) {
36
+ collection.set("timestamps", true);
37
+ await collection.save();
38
+ console.log(`collection name: ${collection.name}`);
39
+ }
40
+ }
41
+ } catch (error) {
42
+ console.error(error);
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,87 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var drop_ui_schema_relation_exports = {};
19
+ __export(drop_ui_schema_relation_exports, {
20
+ default: () => drop_ui_schema_relation_default
21
+ });
22
+ module.exports = __toCommonJS(drop_ui_schema_relation_exports);
23
+ var import_server = require("@tachybase/server");
24
+ class drop_ui_schema_relation_default extends import_server.Migration {
25
+ appVersion = "<0.9.2-alpha.1";
26
+ async up() {
27
+ const result = await this.app.version.satisfies("<0.9.2-alpha.2");
28
+ if (!result) {
29
+ return;
30
+ }
31
+ const transaction = await this.db.sequelize.transaction();
32
+ const migrateFieldsSchema = async (collection) => {
33
+ this.app.logger.info(`Start to migrate ${collection.name} collection's ui schema`);
34
+ const field = collection.setField("uiSchemaUid", {
35
+ type: "string"
36
+ });
37
+ const exists = await field.existsInDb({ transaction });
38
+ if (!exists) {
39
+ collection.removeField("uiSchemaUid");
40
+ return;
41
+ }
42
+ const fieldRecords = await collection.repository.find({
43
+ transaction
44
+ });
45
+ const fieldsCount = await collection.repository.count({
46
+ transaction
47
+ });
48
+ this.app.logger.info(`Total ${fieldsCount} fields need to be migrated`);
49
+ let i = 0;
50
+ for (const fieldRecord of fieldRecords) {
51
+ i++;
52
+ this.app.logger.info(
53
+ `Migrate field ${fieldRecord.get("collectionName")}.${fieldRecord.get("name")}, ${i}/${fieldsCount}`
54
+ );
55
+ const uiSchemaUid = fieldRecord.get("uiSchemaUid");
56
+ if (!uiSchemaUid) {
57
+ continue;
58
+ }
59
+ const uiSchemaRecord = await this.db.getRepository("uiSchemas").findOne({
60
+ filterByTk: uiSchemaUid,
61
+ transaction
62
+ });
63
+ if (!uiSchemaRecord) {
64
+ continue;
65
+ }
66
+ const uiSchema = uiSchemaRecord.get("schema");
67
+ fieldRecord.set("uiSchema", uiSchema);
68
+ await fieldRecord.save({
69
+ transaction
70
+ });
71
+ }
72
+ collection.removeField("uiSchemaUid");
73
+ this.app.logger.info("Migrate uiSchema to options field done");
74
+ };
75
+ try {
76
+ await migrateFieldsSchema(this.db.getCollection("fields"));
77
+ if (this.db.getCollection("fieldsHistory")) {
78
+ await migrateFieldsSchema(this.db.getCollection("fieldsHistory"));
79
+ }
80
+ await transaction.commit();
81
+ } catch (error) {
82
+ await transaction.rollback();
83
+ this.app.logger.error(error);
84
+ throw error;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,5 @@
1
+ import { Migration } from '@tachybase/server';
2
+ export default class extends Migration {
3
+ appVersion: string;
4
+ up(): Promise<void>;
5
+ }
@@ -0,0 +1,77 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var alert_ui_schema_exports = {};
19
+ __export(alert_ui_schema_exports, {
20
+ default: () => alert_ui_schema_default
21
+ });
22
+ module.exports = __toCommonJS(alert_ui_schema_exports);
23
+ var import_server = require("@tachybase/server");
24
+ class alert_ui_schema_default extends import_server.Migration {
25
+ appVersion = "<0.9.3-alpha.1";
26
+ async up() {
27
+ const result = await this.app.version.satisfies("<=0.9.2-alpha.5");
28
+ if (!result) {
29
+ return;
30
+ }
31
+ const transaction = await this.db.sequelize.transaction();
32
+ const migrateFieldsSchema = async (collection) => {
33
+ this.app.logger.info(`Start to migrate ${collection.name} collection's ui schema`);
34
+ const fieldRecords = await collection.repository.find({
35
+ transaction,
36
+ filter: {
37
+ type: ["hasOne", "hasMany", "belongsTo", "belongsToMany"]
38
+ }
39
+ });
40
+ const fieldsCount = await collection.repository.count({
41
+ transaction,
42
+ filter: {
43
+ type: ["hasOne", "hasMany", "belongsTo", "belongsToMany"]
44
+ }
45
+ });
46
+ this.app.logger.info(`Total ${fieldsCount} fields need to be migrated`);
47
+ let i = 0;
48
+ for (const fieldRecord of fieldRecords) {
49
+ i++;
50
+ this.app.logger.info(
51
+ `Migrate field ${fieldRecord.get("collectionName")}.${fieldRecord.get("name")}, ${i}/${fieldsCount}`
52
+ );
53
+ const uiSchema = fieldRecord.get("uiSchema");
54
+ if ((uiSchema == null ? void 0 : uiSchema["x-component"]) !== "RecordPicker") {
55
+ continue;
56
+ }
57
+ console.log(`${fieldRecord.get("collectionName")}.${fieldRecord.get("name")}: ${uiSchema["x-component"]}`);
58
+ uiSchema["x-component"] = "AssociationField";
59
+ fieldRecord.set("uiSchema", uiSchema);
60
+ await fieldRecord.save({
61
+ transaction
62
+ });
63
+ }
64
+ };
65
+ try {
66
+ await migrateFieldsSchema(this.db.getCollection("fields"));
67
+ if (this.db.getCollection("fieldsHistory")) {
68
+ await migrateFieldsSchema(this.db.getCollection("fieldsHistory"));
69
+ }
70
+ await transaction.commit();
71
+ } catch (error) {
72
+ await transaction.rollback();
73
+ this.app.logger.error(error);
74
+ throw error;
75
+ }
76
+ }
77
+ }