@mikro-orm/knex 6.5.6-dev.4 → 6.5.6-dev.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.
@@ -79,7 +79,8 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
79
79
  }
80
80
  const indexName = super.getIndexName(tableName, columns, type);
81
81
  if (indexName.length > 64) {
82
- return `${indexName.substring(0, 56 - type.length)}_${core_1.Utils.hash(indexName, 5)}_${type}`;
82
+ const hashAlgorithm = this.config.get('hashAlgorithm');
83
+ return `${indexName.substring(0, 56 - type.length)}_${core_1.Utils.hash(indexName, 5, hashAlgorithm)}_${type}`;
83
84
  }
84
85
  return indexName;
85
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.5.6-dev.4",
3
+ "version": "6.5.6-dev.6",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.5.5"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.5.6-dev.4",
69
+ "@mikro-orm/core": "6.5.6-dev.6",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -72,6 +72,7 @@ class DatabaseSchema {
72
72
  static fromMetadata(metadata, platform, config, schemaName) {
73
73
  const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema'));
74
74
  const nativeEnums = {};
75
+ const skipColumns = config.get('schemaGenerator').skipColumns || {};
75
76
  for (const meta of metadata) {
76
77
  for (const prop of meta.props) {
77
78
  if (prop.nativeEnumName) {
@@ -100,7 +101,7 @@ class DatabaseSchema {
100
101
  const table = schema.addTable(meta.collection, this.getSchemaName(meta, config, schemaName));
101
102
  table.comment = meta.comment;
102
103
  meta.props
103
- .filter(prop => this.shouldHaveColumn(meta, prop))
104
+ .filter(prop => this.shouldHaveColumn(meta, prop, skipColumns))
104
105
  .forEach(prop => table.addColumnFromProperty(prop, meta, config));
105
106
  meta.indexes.forEach(index => table.addIndex(meta, index, 'index'));
106
107
  meta.uniques.forEach(index => table.addIndex(meta, index, 'unique'));
@@ -129,10 +130,25 @@ class DatabaseSchema {
129
130
  return ((takeTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? true) &&
130
131
  !(skipTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? false));
131
132
  }
132
- static shouldHaveColumn(meta, prop) {
133
+ static shouldHaveColumn(meta, prop, skipColumns) {
133
134
  if (prop.persist === false || (prop.columnTypes?.length ?? 0) === 0) {
134
135
  return false;
135
136
  }
137
+ // Check if column should be skipped
138
+ if (skipColumns) {
139
+ const tableName = meta.tableName;
140
+ const tableSchema = meta.schema;
141
+ const fullTableName = tableSchema ? `${tableSchema}.${tableName}` : tableName;
142
+ // Check for skipColumns by table name or fully qualified table name
143
+ const columnsToSkip = skipColumns[tableName] || skipColumns[fullTableName];
144
+ if (columnsToSkip) {
145
+ for (const fieldName of prop.fieldNames) {
146
+ if (columnsToSkip.some(pattern => this.matchName(fieldName, pattern))) {
147
+ return false;
148
+ }
149
+ }
150
+ }
151
+ }
136
152
  if (prop.kind === core_1.ReferenceKind.EMBEDDED && prop.object) {
137
153
  return true;
138
154
  }
@@ -73,6 +73,8 @@ export declare abstract class SchemaHelper {
73
73
  disableForeignKeys?: boolean;
74
74
  createForeignKeyConstraints?: boolean;
75
75
  ignoreSchema?: string[];
76
+ skipTables?: (string | RegExp)[];
77
+ skipColumns?: Dictionary<(string | RegExp)[]>;
76
78
  managementDbName?: string;
77
79
  };
78
80
  private processComment;
@@ -1,4 +1,4 @@
1
- import { AbstractSchemaGenerator, type ClearDatabaseOptions, type CreateSchemaOptions, type DropSchemaOptions, type EnsureDatabaseOptions, type ISchemaGenerator, type MikroORM, type Transaction, type UpdateSchemaOptions } from '@mikro-orm/core';
1
+ import { AbstractSchemaGenerator, type ClearDatabaseOptions, type CreateSchemaOptions, type DropSchemaOptions, type EnsureDatabaseOptions, type EntityMetadata, type ISchemaGenerator, type MikroORM, type Transaction, type UpdateSchemaOptions } from '@mikro-orm/core';
2
2
  import type { SchemaDifference } from '../typings';
3
3
  import { DatabaseSchema } from './DatabaseSchema';
4
4
  import type { AbstractSqlDriver } from '../AbstractSqlDriver';
@@ -8,6 +8,8 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
8
8
  disableForeignKeys?: boolean;
9
9
  createForeignKeyConstraints?: boolean;
10
10
  ignoreSchema?: string[];
11
+ skipTables?: (string | RegExp)[];
12
+ skipColumns?: import("@mikro-orm/core").Dictionary<(string | RegExp)[]>;
11
13
  managementDbName?: string;
12
14
  };
13
15
  protected lastEnsuredDatabase?: string;
@@ -18,6 +20,7 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
18
20
  */
19
21
  ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
20
22
  getTargetSchema(schema?: string): DatabaseSchema;
23
+ protected getOrderedMetadata(schema?: string): EntityMetadata[];
21
24
  getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
22
25
  dropSchema(options?: DropSchemaOptions): Promise<void>;
23
26
  createNamespace(name: string): Promise<void>;
@@ -60,5 +63,7 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
60
63
  private createForeignKeys;
61
64
  private dump;
62
65
  private get knex();
66
+ private matchName;
67
+ private isTableSkipped;
63
68
  }
64
69
  export { SqlSchemaGenerator as SchemaGenerator };
@@ -50,6 +50,15 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
50
50
  const schemaName = schema ?? this.config.get('schema') ?? this.platform.getDefaultSchemaName();
51
51
  return DatabaseSchema_1.DatabaseSchema.fromMetadata(metadata, this.platform, this.config, schemaName);
52
52
  }
53
+ getOrderedMetadata(schema) {
54
+ const metadata = super.getOrderedMetadata(schema);
55
+ // Filter out skipped tables
56
+ return metadata.filter(meta => {
57
+ const tableName = meta.tableName;
58
+ const tableSchema = meta.schema ?? schema ?? this.config.get('schema');
59
+ return !this.isTableSkipped(tableName, tableSchema);
60
+ });
61
+ }
53
62
  async getCreateSchemaSQL(options = {}) {
54
63
  const toSchema = this.getTargetSchema(options.schema);
55
64
  let ret = '';
@@ -486,6 +495,19 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
486
495
  get knex() {
487
496
  return this.connection.getKnex();
488
497
  }
498
+ matchName(name, nameToMatch) {
499
+ return typeof nameToMatch === 'string'
500
+ ? name.toLocaleLowerCase() === nameToMatch.toLocaleLowerCase()
501
+ : nameToMatch.test(name);
502
+ }
503
+ isTableSkipped(tableName, schemaName) {
504
+ const skipTables = this.options.skipTables;
505
+ if (!skipTables || skipTables.length === 0) {
506
+ return false;
507
+ }
508
+ const fullTableName = schemaName ? `${schemaName}.${tableName}` : tableName;
509
+ return skipTables.some(pattern => this.matchName(tableName, pattern) || this.matchName(fullTableName, pattern));
510
+ }
489
511
  }
490
512
  exports.SqlSchemaGenerator = SqlSchemaGenerator;
491
513
  exports.SchemaGenerator = SqlSchemaGenerator;