@mikro-orm/knex 6.3.14-dev.34 → 6.3.14-dev.36

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.3.14-dev.34",
3
+ "version": "6.3.14-dev.36",
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.3.13"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.3.14-dev.34",
69
+ "@mikro-orm/core": "6.3.14-dev.36",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -34,9 +34,11 @@ export declare class DatabaseSchema {
34
34
  hasNamespace(namespace: string): boolean;
35
35
  hasNativeEnum(name: string): boolean;
36
36
  getNamespaces(): string[];
37
- static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, schemas?: string[]): Promise<DatabaseSchema>;
37
+ static create(connection: AbstractSqlConnection, platform: AbstractSqlPlatform, config: Configuration, schemaName?: string, schemas?: string[], takeTables?: (string | RegExp)[], skipTables?: (string | RegExp)[]): Promise<DatabaseSchema>;
38
38
  static fromMetadata(metadata: EntityMetadata[], platform: AbstractSqlPlatform, config: Configuration, schemaName?: string): DatabaseSchema;
39
39
  private static getSchemaName;
40
+ private static matchName;
41
+ private static isTableNameAllowed;
40
42
  private static shouldHaveColumn;
41
43
  toJSON(): Dictionary;
42
44
  prune(schema: string | undefined, wildcardSchemaTables: string[]): void;
@@ -59,13 +59,13 @@ class DatabaseSchema {
59
59
  getNamespaces() {
60
60
  return [...this.namespaces];
61
61
  }
62
- static async create(connection, platform, config, schemaName, schemas) {
62
+ static async create(connection, platform, config, schemaName, schemas, takeTables, skipTables) {
63
63
  const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema') ?? platform.getDefaultSchemaName());
64
64
  const allTables = await connection.execute(platform.getSchemaHelper().getListTablesSQL());
65
65
  const parts = config.get('migrations').tableName.split('.');
66
66
  const migrationsTableName = parts[1] ?? parts[0];
67
67
  const migrationsSchemaName = parts.length > 1 ? parts[0] : config.get('schema', platform.getDefaultSchemaName());
68
- const tables = allTables.filter(t => t.table_name !== migrationsTableName || (t.schema_name && t.schema_name !== migrationsSchemaName));
68
+ const tables = allTables.filter(t => this.isTableNameAllowed(t.table_name, takeTables, skipTables) && (t.table_name !== migrationsTableName || (t.schema_name && t.schema_name !== migrationsSchemaName)));
69
69
  await platform.getSchemaHelper().loadInformationSchema(schema, connection, tables, schemas && schemas.length > 0 ? schemas : undefined);
70
70
  return schema;
71
71
  }
@@ -120,6 +120,15 @@ class DatabaseSchema {
120
120
  static getSchemaName(meta, config, schema) {
121
121
  return (meta.schema === '*' ? schema : meta.schema) ?? config.get('schema');
122
122
  }
123
+ static matchName(name, nameToMatch) {
124
+ return typeof nameToMatch === 'string'
125
+ ? name.toLocaleLowerCase() === nameToMatch.toLocaleLowerCase()
126
+ : nameToMatch.test(name);
127
+ }
128
+ static isTableNameAllowed(tableName, takeTables, skipTables) {
129
+ return ((takeTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? true) &&
130
+ !(skipTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? false));
131
+ }
123
132
  static shouldHaveColumn(meta, prop) {
124
133
  if (prop.persist === false || (prop.columnTypes?.length ?? 0) === 0) {
125
134
  return false;