feathers-knex-modeler
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "feathers-knex-modeler", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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", |
@@ -90,19 +90,43 @@ /* eslint-disable no-console */ | ||
let errored = false | ||
self.debug(`Modifying column: ${column.name}`) | ||
self.debug(option) | ||
db.schema.alterTable(self.name, (table) => { | ||
try { | ||
let typeOfColumn = option.type | ||
let argument = option.argument | ||
if (_.isFunction(table[column.type](column.name)[typeOfColumn]) === true) { | ||
table[column.type](column.name)[typeOfColumn](argument).alter() | ||
} else { | ||
self.debug(`${typeOfColumn} is not a function. Error occured on table: ${self.name}`) | ||
let alterCommand | ||
let typeOfColumn = option.type | ||
let argument = option.argument | ||
let columnToAlter = table[column.type](column.name) | ||
switch (typeOfColumn) { | ||
case 'notNullable': { | ||
alterCommand = columnToAlter.notNullable() | ||
break | ||
} | ||
} catch (err) { | ||
self.debug(`Failed to alter column on table: ${self.name}`) | ||
self.debug(err) | ||
case 'nullable': { | ||
alterCommand = columnToAlter.nullable() | ||
break | ||
} | ||
case 'primary': { | ||
alterCommand = columnToAlter.primary() | ||
break | ||
} | ||
case 'references': { | ||
alterCommand = columnToAlter.references(argument) | ||
break | ||
} | ||
case 'unique': { | ||
alterCommand = columnToAlter.unique() | ||
break | ||
} | ||
default: { | ||
if (_.isFunction(table[column.type](column.name)[typeOfColumn]) === true) { | ||
alterCommand = columnToAlter[typeOfColumn](argument) | ||
} else { | ||
self.debug(`Unable to find the function to perform the alter on the column: ${column.name}`) | ||
} | ||
} | ||
} | ||
return table | ||
return alterCommand.alter() | ||
}) | ||
.catch((err) => { | ||
let alreadyExists = err.message.indexOf('already exists') !== -1 | ||
let alreadyExists = (err.message.indexOf('already exists') !== -1) | ||
if (alreadyExists === false) { | ||
@@ -109,0 +133,0 @@ errored = err |
@@ -10,12 +10,12 @@ /* eslint-disable no-undef */ | ||
before(function (done) { | ||
db.schema.hasTable(fixtures.testOne.name) | ||
db.schema.hasTable(fixtures.testTwo.name) | ||
.then((hasTable) => { | ||
if (hasTable === true) { | ||
return db.raw(`drop table ${fixtures.testOne.name}`) | ||
return db.raw(`drop table ${fixtures.testTwo.name}`) | ||
} | ||
}) | ||
.then(() => db.schema.hasTable(fixtures.testTwo.name)) | ||
.then(() => db.schema.hasTable(fixtures.testOne.name)) | ||
.then((hasTable) => { | ||
if (hasTable === true) { | ||
return db.raw(`drop table ${fixtures.testTwo.name}`) | ||
return db.raw(`drop table ${fixtures.testOne.name}`) | ||
} | ||
@@ -22,0 +22,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
15638
398