@mikro-orm/sql 7.1.12-dev.0 → 7.1.12-dev.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.
@@ -131,6 +131,8 @@ export declare class PostgreSqlSchemaHelper extends SchemaHelper {
131
131
  * Build the column list for a PostgreSQL index.
132
132
  */
133
133
  protected getIndexColumns(index: IndexDef): string;
134
+ /** Non-default index access methods (gin, gist, brin, hash, ...), normalized to lower case. */
135
+ getIndexAccessMethod(index: IndexDef): string;
134
136
  /**
135
137
  * PostgreSQL-specific index options like fill factor.
136
138
  */
@@ -1118,6 +1118,14 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
1118
1118
  })
1119
1119
  .join(', ');
1120
1120
  }
1121
+ /** Non-default index access methods (gin, gist, brin, hash, ...), normalized to lower case. */
1122
+ getIndexAccessMethod(index) {
1123
+ // `fulltext` is a cross-dialect alias handled via `getFullTextIndexExpression`, not a pg access method
1124
+ if (typeof index.type !== 'string' || ['', 'btree', 'fulltext'].includes(index.type.toLowerCase())) {
1125
+ return '';
1126
+ }
1127
+ return index.type.toLowerCase();
1128
+ }
1121
1129
  /**
1122
1130
  * PostgreSQL-specific index options like fill factor.
1123
1131
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.1.12-dev.0",
3
+ "version": "7.1.12-dev.2",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.1.11"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.12-dev.0"
56
+ "@mikro-orm/core": "7.1.12-dev.2"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -820,6 +820,10 @@ export class SchemaComparator {
820
820
  if (!!index1.clustered !== !!index2.clustered) {
821
821
  return false;
822
822
  }
823
+ // Compare the index access method (e.g. `using gin` on PostgreSQL); unset means the platform default
824
+ if (this.#helper.getIndexAccessMethod(index1) !== this.#helper.getIndexAccessMethod(index2)) {
825
+ return false;
826
+ }
823
827
  // Compare WHERE predicate of partial indexes structurally (whitespace/quoting/casing
824
828
  // are normalized via the same helper used for check constraints).
825
829
  if (this.diffExpression(index1.where ?? '', index2.where ?? '')) {
@@ -70,6 +70,13 @@ export declare abstract class SchemaHelper {
70
70
  * Hook for adding driver-specific index options (e.g., fill factor for PostgreSQL).
71
71
  */
72
72
  protected getCreateIndexSuffix(_index: IndexDef): string;
73
+ /**
74
+ * Normalized index access method (e.g. `gin` on PostgreSQL), empty string when the
75
+ * platform default applies. Used for both DDL emission and index diffing.
76
+ */
77
+ getIndexAccessMethod(_index: IndexDef): string;
78
+ /** Emits the access method between the table name and the column list (e.g. ` using gin`). */
79
+ protected getIndexAccessMethodClause(index: IndexDef): string;
73
80
  /**
74
81
  * Default emits ` where <predicate>` for partial indexes. Only Oracle overrides this to
75
82
  * return `''` (it emulates partials via CASE-WHEN columns). MySQL sidesteps the whole path
@@ -167,13 +167,14 @@ export class SchemaHelper {
167
167
  tableName = this.quote(tableName);
168
168
  const keyName = this.quote(index.keyName);
169
169
  const defer = index.deferMode ? ` deferrable initially ${index.deferMode}` : '';
170
- let sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}`;
170
+ const using = this.getIndexAccessMethodClause(index);
171
+ let sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}${using}`;
171
172
  if (index.unique && index.constraint) {
172
173
  sql = `alter table ${tableName} add constraint ${keyName} unique`;
173
174
  }
174
175
  if (index.columnNames.some(column => column.includes('.'))) {
175
176
  // JSON columns can have unique index but not unique constraint, and we need to distinguish those, so we can properly drop them
176
- sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}`;
177
+ sql = `create ${index.unique ? 'unique ' : ''}index ${keyName} on ${tableName}${using}`;
177
178
  const columns = this.platform.getJsonIndexDefinition(index);
178
179
  return `${sql} (${columns.join(', ')})${this.getCreateIndexSuffix(index)}${this.getIndexWhereClause(index)}${defer}`;
179
180
  }
@@ -192,6 +193,18 @@ export class SchemaHelper {
192
193
  getCreateIndexSuffix(_index) {
193
194
  return '';
194
195
  }
196
+ /**
197
+ * Normalized index access method (e.g. `gin` on PostgreSQL), empty string when the
198
+ * platform default applies. Used for both DDL emission and index diffing.
199
+ */
200
+ getIndexAccessMethod(_index) {
201
+ return '';
202
+ }
203
+ /** Emits the access method between the table name and the column list (e.g. ` using gin`). */
204
+ getIndexAccessMethodClause(index) {
205
+ const method = this.getIndexAccessMethod(index);
206
+ return method ? ` using ${method}` : '';
207
+ }
195
208
  /**
196
209
  * Default emits ` where <predicate>` for partial indexes. Only Oracle overrides this to
197
210
  * return `''` (it emulates partials via CASE-WHEN columns). MySQL sidesteps the whole path