feathers-knex-modeler
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "feathers-knex-modeler", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "This package allows you to easily extend a table while you are developing it without requiring you to drop tables.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -93,12 +93,12 @@ /* eslint-disable no-console */ | ||
const self = this | ||
await pWaitFor(async () => self.hasColumn(tableName, columnName)) | ||
return pWaitFor(async () => self.hasColumn(tableName, columnName)) | ||
} | ||
alterColumn (column, option) { | ||
return new Promise((resolve, reject) => { | ||
const self = this | ||
const db = self.db | ||
let errored = false | ||
self.debug(`Modifying column: ${column.name}`) | ||
self.debug(option) | ||
db.schema.alterTable(self.name, (table) => { | ||
async alterColumn (column, option) { | ||
const self = this | ||
const db = self.db | ||
let errored = false | ||
self.debug(`Modifying column: ${column.name}`) | ||
self.debug(option) | ||
try { | ||
await db.schema.alterTable(self.name, (table) => { | ||
let alterCommand | ||
@@ -115,3 +115,2 @@ let typeOfColumn = option.type | ||
} | ||
switch (typeOfColumn) { | ||
@@ -146,19 +145,16 @@ case 'notNullable': { | ||
} | ||
return alterCommand.alter() | ||
alterCommand.alter() | ||
}) | ||
.catch((err) => { | ||
let alreadyExists = (err.message.indexOf('already exists') !== -1) | ||
if (alreadyExists === false) { | ||
errored = err | ||
} | ||
return err | ||
}) | ||
.then(() => { | ||
if (errored === false) { | ||
return resolve() | ||
} else { | ||
return reject(errored) | ||
} | ||
}) | ||
}) | ||
} catch (err) { | ||
let alreadyExists = (err.message.indexOf('already exists') !== -1) | ||
if (alreadyExists === false) { | ||
errored = err | ||
} | ||
} | ||
if (errored === false) { | ||
return true | ||
} else { | ||
throw errored | ||
} | ||
} | ||
@@ -184,21 +180,20 @@ async createColumn (column) { | ||
} | ||
alterTable (hasColumn, column) { | ||
return new Promise((resolve, reject) => { | ||
const self = this | ||
const db = self.db | ||
db.schema.alterTable(self.name, (table) => { | ||
let alterations = [] | ||
if (hasColumn === false) { | ||
table[column.type](column.name) | ||
return resolve(self.alterTable(true, column)) | ||
} else { | ||
for (let optionIndex = 0; optionIndex < column.options.length; optionIndex++) { | ||
alterations.push(self.alterColumn(column, column.options[optionIndex])) | ||
} | ||
return Promise.all(alterations) | ||
async alterTable (hasColumn, column) { | ||
const self = this | ||
const db = self.db | ||
let alterations = [] | ||
await db.schema.alterTable(self.name, (table) => { | ||
if (hasColumn === false) { | ||
table[column.type](column.name) | ||
} else { | ||
for (let optionIndex = 0; optionIndex < column.options.length; optionIndex++) { | ||
alterations.push(self.alterColumn(column, column.options[optionIndex])) | ||
} | ||
}) | ||
.then(() => resolve()) | ||
.catch((err) => reject(err)) | ||
} | ||
}) | ||
if (hasColumn === false) { | ||
return self.alterTable(true, column) | ||
} else { | ||
return Promise.all(alterations) | ||
} | ||
} | ||
@@ -261,7 +256,8 @@ async createColumns () { | ||
const self = this | ||
let dependedOnTables = [] | ||
for (let dependsIndex = 0; dependsIndex < self.depends.length; dependsIndex++) { | ||
let dependedOnTableName = self.depends[dependsIndex] | ||
await self.hasTable(dependedOnTableName) | ||
dependedOnTables.push(self.hasTable(dependedOnTableName)) | ||
} | ||
return true | ||
return Promise.all(dependedOnTables) | ||
} | ||
@@ -268,0 +264,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16074
407