mirror of
https://github.com/knex/knex.git
synced 2025-06-26 22:00:25 +00:00
Co-authored-by: David Farrugia <david.farrugia@sagossgroup.com>
This commit is contained in:
parent
0a29f6c5d0
commit
770b2f20ac
@ -160,6 +160,14 @@ class TableCompiler_MySQL extends TableCompiler {
|
||||
}
|
||||
});
|
||||
}
|
||||
const bigIncrementsCols = this._getBigIncrementsColumnNames();
|
||||
if (bigIncrementsCols.length) {
|
||||
bigIncrementsCols.forEach((c) => {
|
||||
if (!columns.includes(c)) {
|
||||
columns.unshift(c);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return `,${constraintName} primary key (${this.formatter.columnize(
|
||||
@ -292,6 +300,7 @@ class TableCompiler_MySQL extends TableCompiler {
|
||||
|
||||
const primaryCols = columns;
|
||||
let incrementsCols = [];
|
||||
let bigIncrementsCols = [];
|
||||
if (this.grouped.columns) {
|
||||
incrementsCols = this._getIncrementsColumnNames();
|
||||
if (incrementsCols) {
|
||||
@ -301,6 +310,14 @@ class TableCompiler_MySQL extends TableCompiler {
|
||||
}
|
||||
});
|
||||
}
|
||||
bigIncrementsCols = this._getBigIncrementsColumnNames();
|
||||
if (bigIncrementsCols) {
|
||||
bigIncrementsCols.forEach((c) => {
|
||||
if (!primaryCols.includes(c)) {
|
||||
primaryCols.unshift(c);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.method !== 'create' && this.method !== 'createIfNot') {
|
||||
this.pushQuery(
|
||||
@ -316,6 +333,13 @@ class TableCompiler_MySQL extends TableCompiler {
|
||||
)} int unsigned not null auto_increment`
|
||||
);
|
||||
}
|
||||
if (bigIncrementsCols.length) {
|
||||
this.pushQuery(
|
||||
`alter table ${this.tableName()} modify column ${this.formatter.columnize(
|
||||
bigIncrementsCols
|
||||
)} bigint unsigned not null auto_increment`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unique(columns, indexName) {
|
||||
|
@ -418,6 +418,12 @@ class TableCompiler {
|
||||
.filter((c) => c.builder._type === 'increments')
|
||||
.map((c) => c.builder._args[0]);
|
||||
}
|
||||
|
||||
_getBigIncrementsColumnNames() {
|
||||
return this.grouped.columns
|
||||
.filter((c) => c.builder._type === 'bigincrements')
|
||||
.map((c) => c.builder._args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
TableCompiler.prototype.pushQuery = pushQuery;
|
||||
|
@ -723,6 +723,25 @@ module.exports = function (dialect) {
|
||||
);
|
||||
});
|
||||
|
||||
it('test basic create table with composite key on big incrementing column + other', function () {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.createTable('users', function (table) {
|
||||
table.primary(['userId', 'name']);
|
||||
table.bigincrements('userId');
|
||||
table.string('name');
|
||||
})
|
||||
.toSQL();
|
||||
|
||||
equal(2, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'create table `users` (`userId` bigint unsigned not null, `name` varchar(255), primary key (`userId`, `name`))'
|
||||
);
|
||||
expect(tableSql[1].sql).to.equal(
|
||||
'alter table `users` modify column `userId` bigint unsigned not null auto_increment'
|
||||
);
|
||||
});
|
||||
|
||||
it('test adding column after another column', function () {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
|
Loading…
x
Reference in New Issue
Block a user