Skip to content

Commit

Permalink
fix migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Dec 13, 2019
1 parent 0628b2e commit 1f11568
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lib/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,20 @@ function mixinMigration(PostgreSQL) {
let result = self.columnDataType(model, propName);
// checks if dataType is set to uuid
let postgreType = modelDef.properties[propName];
if(postgreType.postgresql && postgreType.postgresql.dataType){
if (postgreType.postgresql && postgreType.postgresql.dataType) {
postgreType = postgreType.postgresql.dataType.toUpperCase();
}

if (prop.generated) {
if (result === 'INTEGER') {
return 'SERIAL';
}
else if (postgreType === 'UUID') {
} else if (postgreType === 'UUID') {
result = result + ' NOT NULL' + ' DEFAULT uuid_generate_v4()';
return result;
} else {
console.log(chalk.red('>>> WARNING: ') +
`auto-generattion is not supported for type "${chalk.yellow(prop.type)}". Please add your own function to the table "${chalk.yellow(model)}".`
);
`auto-generattion is not supported for type "${chalk.yellow(prop.type)}". \
Please add your own function to the table "${chalk.yellow(model)}".`);
}
}

Expand All @@ -336,28 +335,29 @@ function mixinMigration(PostgreSQL) {
'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";' +
'CREATE SCHEMA ' +
self.escapeName(self.schema(model)),
function(err) {
if (err && err.code !== '42P06') {
return cb && cb(err);
}
self.execute('CREATE TABLE ' + name + ' (\n ' +
self.propertiesSQL(model) + '\n)',
function(err, info) {
if (err) {
return cb(err, info);
function(err) {
if (err && err.code !== '42P06') {
return cb && cb(err);
}
self.addIndexes(model, undefined, function(err) {
self.execute('CREATE TABLE ' + name + ' (\n ' +
self.propertiesSQL(model) + '\n)',
function(err, info) {
if (err) {
return cb(err);
return cb(err, info);
}
const fkSQL = self.getForeignKeySQL(model,
self.getModelDefinition(model).settings.foreignKeys);
self.addForeignKeys(model, fkSQL, function(err, result) {
cb(err);
self.addIndexes(model, undefined, function(err) {
if (err) {
return cb(err);
}
const fkSQL = self.getForeignKeySQL(model,
self.getModelDefinition(model).settings.foreignKeys);
self.addForeignKeys(model, fkSQL, function(err, result) {
cb(err);
});
});
});
});
});
},
);
};

PostgreSQL.prototype.buildIndex = function(model, property) {
Expand Down

0 comments on commit 1f11568

Please sign in to comment.