Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSSQL removes support column width/length on data type int #2738

Merged
merged 7 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/dialects/mssql/schema/columncompiler.js
Expand Up @@ -30,18 +30,18 @@ assign(ColumnCompiler_MSSQL.prototype, {
return `float`;
},

integer(length) {
length = length ? `(${this._num(length, 11)})` : '';
return `int${length}`;
integer() {
// mssql does not support length
return 'int';
},

mediumint: 'int',

smallint: 'smallint',

tinyint(length) {
length = length ? `(${this._num(length, 1)})` : '';
return `tinyint${length}`;
tinyint() {
// mssql does not support length
return 'tinyint';
},

varchar(length) {
Expand Down
43 changes: 43 additions & 0 deletions test/integration/schema/index.js
Expand Up @@ -447,6 +447,35 @@ module.exports = function(knex) {
});
});

it('handles numeric length correctly', function() {
return knex.schema
.createTable('test_table_numerics', function(table) {
table.engine('InnoDB');
table.integer('integer_column', 5);
table.tinyint('tinyint_column', 5);
table.smallint('smallint_column', 5);
table.mediumint('mediumint_column', 5);
table.bigint('bigint_column', 5);
})
.testSql(function(tester) {
tester('mysql', [
'create table `test_table_numerics` (`integer_column` int(5), `tinyint_column` tinyint(5), `smallint_column` smallint, `mediumint_column` mediumint, `bigint_column` bigint) default character set utf8 engine = InnoDB',
]);
tester('pg', [
'create table "test_table_numerics" ("integer_column" integer, "tinyint_column" smallint, "smallint_column" smallint, "mediumint_column" integer, "bigint_column" bigint)',
]);
tester('sqlite3', [
'create table `test_table_numerics` (`integer_column` integer, `tinyint_column` tinyint, `smallint_column` integer, `mediumint_column` integer, `bigint_column` bigint)',
]);
tester('mssql', [
'CREATE TABLE [test_table_numerics] ([integer_column] int, [tinyint_column] tinyint, [smallint_column] smallint, [mediumint_column] int, [bigint_column] bigint)',
]);
})
.then(function() {
return knex.schema.dropTable('test_table_numerics');
});
});

it('supports the enum and uuid columns', function() {
// NB: redshift does not...
return knex.schema
Expand Down Expand Up @@ -775,6 +804,20 @@ module.exports = function(knex) {
});
});

it('handles creating numeric columns with specified length correctly', function() {
return knex.schema
.createTable('test_table_numerics2', function(table) {
table.integer('integer_column', 5);
table.tinyint('tinyint_column', 5);
table.smallint('smallint_column', 5);
table.mediumint('mediumint_column', 5);
table.bigint('bigint_column', 5);
})
.then(function() {
return knex.schema.dropTable('test_table_numerics2');
});
});

it('allows alter column syntax', function() {
if (
knex.client.driverName.match('sqlite3') ||
Expand Down