Honor user specified datatype on PKs
This commit is contained in:
parent
881f1584ed
commit
2ded0f96eb
|
@ -582,8 +582,8 @@ function mixinMigration(MySQL, mysql) {
|
|||
var idName = this.idName(model);
|
||||
var idProp = this.getModelDefinition(model).properties[idName];
|
||||
if (idProp.generated) {
|
||||
sql.push(self.columnEscaped(model, idName) +
|
||||
' INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY');
|
||||
sql.push(self.columnEscaped(model, idName) + ' ' +
|
||||
self.buildColumnDefinition(model, idName) + ' AUTO_INCREMENT PRIMARY KEY');
|
||||
} else {
|
||||
idProp.nullable = false;
|
||||
sql.push(self.columnEscaped(model, idName) + ' ' +
|
||||
|
|
|
@ -10,7 +10,7 @@ var platform = require('./helpers/platform');
|
|||
var should = require('./init');
|
||||
var Schema = require('loopback-datasource-juggler').Schema;
|
||||
|
||||
var db, UserData, StringData, NumberData, DateData;
|
||||
var db, UserData, StringData, NumberData, DateData, SimpleEmployee;
|
||||
var mysqlVersion;
|
||||
|
||||
describe('migrations', function() {
|
||||
|
@ -22,6 +22,16 @@ describe('migrations', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('allow user specified datatype on PK', function(done) {
|
||||
query('describe SimpleEmployee', function(err, result) {
|
||||
should.not.exist(err);
|
||||
should.exist(result);
|
||||
result[0].Key.should.equal('PRI');
|
||||
result[0].Type.should.equal('bigint(20)');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('UserData should have correct columns', function(done) {
|
||||
getFields('UserData', function(err, fields) {
|
||||
if (!fields) return done();
|
||||
|
@ -498,6 +508,11 @@ function setup(done) {
|
|||
timestamp: {type: Date, dataType: 'timestamp'},
|
||||
});
|
||||
|
||||
SimpleEmployee = db.define('SimpleEmployee', {
|
||||
eId: {type: Number, generated: true, id: true, mysql: {dataType: 'bigint', dataLength: 20}},
|
||||
name: {type: String},
|
||||
});
|
||||
|
||||
query('SELECT VERSION()', function(err, res) {
|
||||
mysqlVersion = res && res[0] && res[0]['VERSION()'];
|
||||
blankDatabase(db, done);
|
||||
|
|
Loading…
Reference in New Issue