@mikro-orm/knex 6.3.13-dev.2 → 6.3.13-dev.4
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BaseMySqlColumnCompiler from 'knex/lib/dialects/mysql/schema/mysql-columncompiler';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MySqlIncrementOptions } from '../../typings';
|
|
3
3
|
export declare class MySqlColumnCompiler extends BaseMySqlColumnCompiler {
|
|
4
|
-
increments(options:
|
|
5
|
-
bigincrements(options:
|
|
4
|
+
increments(options: MySqlIncrementOptions): string;
|
|
5
|
+
bigincrements(options: MySqlIncrementOptions): string;
|
|
6
6
|
private generateDDL;
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
|
-
import type { CheckDef, Column, IndexDef, TableDifference, Table, ForeignKey } from '../../typings';
|
|
2
|
+
import type { CheckDef, Column, IndexDef, TableDifference, Table, ForeignKey, MySqlTableBuilder } from '../../typings';
|
|
3
3
|
import { type Dictionary, type Type } from '@mikro-orm/core';
|
|
4
4
|
import type { AbstractSqlConnection } from '../../AbstractSqlConnection';
|
|
5
5
|
import { SchemaHelper } from '../../schema/SchemaHelper';
|
|
6
6
|
import type { DatabaseSchema } from '../../schema/DatabaseSchema';
|
|
7
|
+
import type { DatabaseTable } from '../../schema/DatabaseTable';
|
|
7
8
|
export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
8
9
|
private readonly _cache;
|
|
9
10
|
static readonly DEFAULT_VALUES: {
|
|
@@ -22,6 +23,7 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
22
23
|
getAllChecks(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<CheckDef[]>>;
|
|
23
24
|
getAllForeignKeys(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<Dictionary<ForeignKey>>>;
|
|
24
25
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
|
26
|
+
createTableColumn(table: MySqlTableBuilder, column: Column, fromTable: DatabaseTable, changedProperties?: Set<string>, alter?: boolean): Knex.ColumnBuilder | undefined;
|
|
25
27
|
configureColumnDefault(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
26
28
|
getRenameColumnSQL(tableName: string, oldColumnName: string, to: Column): string;
|
|
27
29
|
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
|
|
@@ -180,6 +180,24 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
|
|
|
180
180
|
.map(col => `alter table \`${tableDiff.name}\` modify \`${col.name}\` ${this.getColumnDeclarationSQL({ ...col, autoincrement: false })}`)
|
|
181
181
|
.join(';\n');
|
|
182
182
|
}
|
|
183
|
+
createTableColumn(table, column, fromTable, changedProperties, alter) {
|
|
184
|
+
const compositePK = fromTable.getPrimaryKey()?.composite;
|
|
185
|
+
if (column.autoincrement && !column.generated && !compositePK && column.primary) {
|
|
186
|
+
const primaryKey = !changedProperties && !this.hasNonDefaultPrimaryKeyName(fromTable);
|
|
187
|
+
if (column.mappedType instanceof core_1.BigIntType) {
|
|
188
|
+
return table.bigIncrements(column.name, { primaryKey, unsigned: column.unsigned, type: column.type });
|
|
189
|
+
}
|
|
190
|
+
return table.increments(column.name, { primaryKey, unsigned: column.unsigned, type: column.type });
|
|
191
|
+
}
|
|
192
|
+
if (column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) {
|
|
193
|
+
return table.enum(column.name, column.enumItems);
|
|
194
|
+
}
|
|
195
|
+
let columnType = column.type;
|
|
196
|
+
if (column.generated) {
|
|
197
|
+
columnType += ` generated always as ${column.generated}`;
|
|
198
|
+
}
|
|
199
|
+
return table.specificType(column.name, columnType);
|
|
200
|
+
}
|
|
183
201
|
configureColumnDefault(column, col, knex, changedProperties) {
|
|
184
202
|
if (changedProperties || column.default !== undefined) {
|
|
185
203
|
if (column.default == null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.3.13-dev.
|
|
3
|
+
"version": "6.3.13-dev.4",
|
|
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.12"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.3.13-dev.
|
|
69
|
+
"@mikro-orm/core": "6.3.13-dev.4",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type Connection, type Dictionary } from '@mikro-orm/core';
|
|
|
2
2
|
import type { Knex } from 'knex';
|
|
3
3
|
import type { AbstractSqlConnection } from '../AbstractSqlConnection';
|
|
4
4
|
import type { AbstractSqlPlatform } from '../AbstractSqlPlatform';
|
|
5
|
-
import type { CheckDef, Column,
|
|
5
|
+
import type { CheckDef, Column, ForeignKey, IndexDef, Table, TableDifference } from '../typings';
|
|
6
6
|
import type { DatabaseSchema } from './DatabaseSchema';
|
|
7
7
|
import type { DatabaseTable } from './DatabaseTable';
|
|
8
8
|
export declare abstract class SchemaHelper {
|
|
@@ -30,7 +30,7 @@ export declare abstract class SchemaHelper {
|
|
|
30
30
|
getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string;
|
|
31
31
|
getDropColumnsSQL(tableName: string, columns: Column[], schemaName?: string): string;
|
|
32
32
|
hasNonDefaultPrimaryKeyName(table: DatabaseTable): boolean;
|
|
33
|
-
createTableColumn(table:
|
|
33
|
+
createTableColumn(table: Knex.TableBuilder, column: Column, fromTable: DatabaseTable, changedProperties?: Set<string>, alter?: boolean): Knex.ColumnBuilder | undefined;
|
|
34
34
|
configureColumn(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
35
35
|
configureColumnDefault(column: Column, col: Knex.ColumnBuilder, knex: Knex, changedProperties?: Set<string>): Knex.ColumnBuilder;
|
|
36
36
|
getPreAlterTable(tableDiff: TableDifference, safe: boolean): string;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -126,12 +126,12 @@ class SchemaHelper {
|
|
|
126
126
|
}
|
|
127
127
|
createTableColumn(table, column, fromTable, changedProperties, alter) {
|
|
128
128
|
const compositePK = fromTable.getPrimaryKey()?.composite;
|
|
129
|
-
if (column.autoincrement && !column.generated && !compositePK &&
|
|
129
|
+
if (column.autoincrement && !column.generated && !compositePK && (!changedProperties || changedProperties.has('autoincrement') || changedProperties.has('type'))) {
|
|
130
130
|
const primaryKey = !changedProperties && !this.hasNonDefaultPrimaryKeyName(fromTable);
|
|
131
131
|
if (column.mappedType instanceof core_1.BigIntType) {
|
|
132
|
-
return table.bigIncrements(column.name, { primaryKey
|
|
132
|
+
return table.bigIncrements(column.name, { primaryKey });
|
|
133
133
|
}
|
|
134
|
-
return table.increments(column.name, { primaryKey
|
|
134
|
+
return table.increments(column.name, { primaryKey });
|
|
135
135
|
}
|
|
136
136
|
if (column.mappedType instanceof core_1.EnumType && column.enumItems?.every(item => core_1.Utils.isString(item))) {
|
|
137
137
|
return table.enum(column.name, column.enumItems);
|
package/typings.d.ts
CHANGED
|
@@ -185,13 +185,13 @@ export interface ICriteriaNode<T extends object> {
|
|
|
185
185
|
getPath(addIndex?: boolean): string;
|
|
186
186
|
getPivotPath(path: string): string;
|
|
187
187
|
}
|
|
188
|
-
export type
|
|
188
|
+
export type MySqlIncrementOptions = {
|
|
189
189
|
primaryKey?: boolean;
|
|
190
190
|
unsigned?: boolean;
|
|
191
191
|
type?: Column['type'];
|
|
192
192
|
};
|
|
193
|
-
export interface
|
|
194
|
-
increments(columnName?: string, options?:
|
|
195
|
-
bigIncrements(columnName?: string, options?:
|
|
193
|
+
export interface MySqlTableBuilder extends Knex.TableBuilder {
|
|
194
|
+
increments(columnName?: string, options?: MySqlIncrementOptions): Knex.ColumnBuilder;
|
|
195
|
+
bigIncrements(columnName?: string, options?: MySqlIncrementOptions): Knex.ColumnBuilder;
|
|
196
196
|
}
|
|
197
197
|
export {};
|