不要怂,就是干,撸起袖子干!

Commit 74d2b5f1 by Michael McCabe Committed by Sushant

fix(mysql/datatypes): no default null value for some data types (#8839)

1 parent 3397b237
...@@ -310,7 +310,8 @@ const QueryGenerator = { ...@@ -310,7 +310,8 @@ const QueryGenerator = {
}; };
} }
let template = attribute.type.toString({ escape: this.escape.bind(this) }); const attributeString = attribute.type.toString({ escape: this.escape.bind(this) });
let template = attributeString;
if (attribute.allowNull === false) { if (attribute.allowNull === false) {
template += ' NOT NULL'; template += ' NOT NULL';
...@@ -320,8 +321,8 @@ const QueryGenerator = { ...@@ -320,8 +321,8 @@ const QueryGenerator = {
template += ' auto_increment'; template += ' auto_increment';
} }
// Blobs/texts cannot have a defaultValue // BLOB/TEXT/GEOMETRY/JSON cannot have a default value
if (attribute.type !== 'TEXT' && attribute.type._binary !== true && Utils.defaultValueSchemable(attribute.defaultValue)) { if (!_.includes(['BLOB', 'TEXT', 'GEOMETRY', 'JSON'], attributeString) && attribute.type._binary !== true && Utils.defaultValueSchemable(attribute.defaultValue)) {
template += ' DEFAULT ' + this.escape(attribute.defaultValue); template += ' DEFAULT ' + this.escape(attribute.defaultValue);
} }
......
...@@ -75,7 +75,27 @@ if (dialect === 'mysql') { ...@@ -75,7 +75,27 @@ if (dialect === 'mysql') {
arguments: [{id: {type: 'INTEGER', after: 'Bar'}}], arguments: [{id: {type: 'INTEGER', after: 'Bar'}}],
expectation: {id: 'INTEGER AFTER `Bar`'} expectation: {id: 'INTEGER AFTER `Bar`'}
}, },
// No Default Values allowed for certain types
{
title: 'No Default value for MySQL BLOB allowed',
arguments: [{id: {type: 'BLOB', defaultValue: []}}],
expectation: {id: 'BLOB'}
},
{
title: 'No Default value for MySQL TEXT allowed',
arguments: [{id: {type: 'TEXT', defaultValue: []}}],
expectation: {id: 'TEXT'}
},
{
title: 'No Default value for MySQL GEOMETRY allowed',
arguments: [{id: {type: 'GEOMETRY', defaultValue: []}}],
expectation: {id: 'GEOMETRY'}
},
{
title: 'No Default value for MySQL JSON allowed',
arguments: [{id: {type: 'JSON', defaultValue: []}}],
expectation: {id: 'JSON'}
},
// New references style // New references style
{ {
arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}], arguments: [{id: {type: 'INTEGER', references: { model: 'Bar' }}}],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!