@tachybase/database 1.6.12 → 1.6.13-alpha.2

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.
@@ -32,7 +32,7 @@ const _SortField = class _SortField extends import_field.Field {
32
32
  this.setSortValue = /* @__PURE__ */ __name(async (instance, options) => {
33
33
  const { name, scopeKey } = this.options;
34
34
  const { model } = this.context.collection;
35
- if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] === instance[scopeKey]) {
35
+ if ((0, import_lodash.isNumber)(instance.get(name)) && (options.skipSortScopeChangeAppend || instance._previousDataValues[scopeKey] === instance[scopeKey])) {
36
36
  return;
37
37
  }
38
38
  const where = {};
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { BaseError, DataTypes, fn, literal, Op, Transaction, UniqueConstraintError, ValidationError, ValidationErrorItem, where, } from 'sequelize';
2
- export type { BelongsToGetAssociationMixin, HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, ModelStatic, SyncOptions, } from 'sequelize';
1
+ export { BaseError, col, DataTypes, fn, literal, Op, Transaction, UniqueConstraintError, ValidationError, ValidationErrorItem, where, } from 'sequelize';
2
+ export type { BelongsToGetAssociationMixin, HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, ModelStatic, SyncOptions, WhereOptions, } from 'sequelize';
3
3
  export * from './collection';
4
4
  export * from './collection-group-manager';
5
5
  export * from './collection-importer';
package/lib/index.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  UniqueConstraintError: () => import_sequelize.UniqueConstraintError,
37
37
  ValidationError: () => import_sequelize.ValidationError,
38
38
  ValidationErrorItem: () => import_sequelize.ValidationErrorItem,
39
+ col: () => import_sequelize.col,
39
40
  default: () => import_database.Database,
40
41
  fn: () => import_sequelize.fn,
41
42
  literal: () => import_sequelize.literal,
@@ -83,6 +84,7 @@ __reExport(index_exports, require("./utils"), module.exports);
83
84
  UniqueConstraintError,
84
85
  ValidationError,
85
86
  ValidationErrorItem,
87
+ col,
86
88
  fn,
87
89
  literal,
88
90
  snakeCase,
@@ -87,6 +87,7 @@ export interface UpdateOptions extends Omit<SequelizeUpdateOptions, 'where'> {
87
87
  updateAssociationValues?: AssociationKeysToBeUpdate;
88
88
  targetCollection?: string;
89
89
  context?: any;
90
+ skipSortScopeChangeAppend?: boolean;
90
91
  /**
91
92
  * false: will not update updateAt field, default: false
92
93
  * @default false
@@ -189,6 +189,24 @@ const _SyncRunner = class _SyncRunner {
189
189
  });
190
190
  }
191
191
  }
192
+ const uniqueIndexes = this.model["_indexes"].filter((index) => index.unique);
193
+ for (const uniqueIndex of uniqueIndexes) {
194
+ const columnNames = uniqueIndex.fields.map((field) => {
195
+ var _a;
196
+ return ((_a = this.rawAttributes[field]) == null ? void 0 : _a.field) || field;
197
+ });
198
+ const indexExists = existsUniqueIndexes.find((index) => {
199
+ const indexFields = index.fields.map((field) => field.attribute).sort();
200
+ return JSON.stringify(indexFields) === JSON.stringify([...columnNames].sort());
201
+ });
202
+ if (!indexExists) {
203
+ await this.queryInterface.addIndex(this.tableName, columnNames, {
204
+ ...uniqueIndex,
205
+ fields: void 0,
206
+ transaction: options == null ? void 0 : options.transaction
207
+ });
208
+ }
209
+ }
192
210
  }
193
211
  async getColumns(options) {
194
212
  return await this.queryInterface.describeTable(this.tableName, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/database",
3
- "version": "1.6.12",
3
+ "version": "1.6.13-alpha.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/tegojs/tego#readme",
6
6
  "bugs": {
@@ -31,9 +31,9 @@
31
31
  "semver": "7.7.2",
32
32
  "sequelize": "^6.37.7",
33
33
  "umzug": "^3.8.2",
34
- "@tachybase/globals": "1.6.12",
35
- "@tachybase/logger": "1.6.12",
36
- "@tachybase/utils": "1.6.12"
34
+ "@tachybase/globals": "1.6.13-alpha.2",
35
+ "@tachybase/logger": "1.6.13-alpha.2",
36
+ "@tachybase/utils": "1.6.13-alpha.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/flat": "^5.0.5",