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

Set comment size warning limit to 1024 in MySQL #4867

Merged
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
5 changes: 3 additions & 2 deletions lib/dialects/mysql/schema/mysql-tablecompiler.js
Expand Up @@ -42,9 +42,10 @@ class TableCompiler_MySQL extends TableCompiler {

if (this.single.comment) {
const comment = this.single.comment || '';
if (comment.length > 60)
const MAX_COMMENT_LENGTH = 1024;
if (comment.length > MAX_COMMENT_LENGTH)
this.client.logger.warn(
'The max length for a table comment is 60 characters'
`The max length for a table comment is ${MAX_COMMENT_LENGTH} characters`
);
sql += ` comment = '${comment}'`;
}
Expand Down
36 changes: 36 additions & 0 deletions test/unit/schema-builder/mysql.js
Expand Up @@ -1195,6 +1195,42 @@ module.exports = function (dialect) {
}).to.throw(TypeError);
});

it('set comment to old comment limit (size 60+) #4863', function () {
const warnMessages = [];
client.logger = {
warn: (msg) => {
warnMessages.push(msg);
},
};
client
.schemaBuilder()
.createTable('user', function (t) {
t.comment(
"A big comment. If we write more than 60 characters here it shouldn't trigger any warning since mysql and mariaDB maximum length is 1024 characters. Please fix this warning, it's annoying when a migration is taking place with multiple long comments."
);
})
.toSQL();
expect(warnMessages.length).to.equal(0);
});

it('set comment to current comment limit (size 1024+) #4863', function () {
const warnMessages = [];
client.logger = {
warn: (msg) => {
warnMessages.push(msg);
},
};
client
.schemaBuilder()
.createTable('users', function (t) {
t.comment('big comment'.repeat(100));
})
.toSQL();
expect(warnMessages[0]).to.equal(
'The max length for a table comment is 1024 characters'
);
});

it('should alter columns with the alter flag', function () {
tableSql = client
.schemaBuilder()
Expand Down