db-migrate
Advanced tools
Comparing version 0.1.5 to 0.2.0
@@ -37,2 +37,15 @@ ## 0.1.0 | ||
- Fix dropTable on PostgreSQL #21 | ||
- Implement removeColumn and changeColumn for MySQL | ||
- Implement removeColumn and changeColumn for MySQL | ||
## 0.2.0 | ||
New Feature: | ||
- Expose currently running environment name #22 | ||
- Added an insert method to the API #23 | ||
- Add support for unknown column data types #34 | ||
Fix: | ||
- Fixed error creating migration table #26 | ||
- Fixed removeIndex error in MySQL #37 | ||
- Fixed issue with tests using too many connections under PostgreSQL | ||
- Fixed error running migrations under sqlite3 #27 |
@@ -5,2 +5,3 @@ var driver = require('./lib/driver'); | ||
exports.dataType = require('./lib/data_type'); | ||
exports.config = require('./lib/config'); | ||
@@ -7,0 +8,0 @@ exports.connect = function(config, callback) { |
@@ -34,3 +34,3 @@ var fs = require('fs'); | ||
var setCurrent = exports.setCurrent = function(env) { | ||
var setCurrent = exports.setCurrent = function (env) { | ||
env = dbmUtil.isArray(env) ? env : [env]; | ||
@@ -40,4 +40,7 @@ | ||
if (dbmUtil.isString(current) && exports[current]) { | ||
exports.getCurrent = function() { | ||
return exports[current]; | ||
exports.getCurrent = function () { | ||
return { | ||
env: current, | ||
settings: exports[current] | ||
} | ||
} | ||
@@ -44,0 +47,0 @@ } |
@@ -22,3 +22,3 @@ var util = require('util'); | ||
case type.STRING: | ||
return 'VARCHAR(255)'; | ||
return 'VARCHAR'; | ||
case type.TEXT: | ||
@@ -35,3 +35,5 @@ return 'TEXT'; | ||
default: | ||
throw new Error('Invalid data type ' + str); | ||
var unknownType = str.toUpperCase(); | ||
log.warn('Using unknown data type', unknownType); | ||
return unknownType; | ||
} | ||
@@ -148,2 +150,30 @@ }, | ||
insert: function(tableName, columnNameArray, valueArray, callback) { | ||
if (columnNameArray.length !== valueArray.length) { | ||
return callback(new Error('The number of columns does not match the number of values.')); | ||
} | ||
var sql = util.format('INSERT INTO %s ', tableName); | ||
var columnNames = '('; | ||
var values = 'VALUES ('; | ||
for (var index in columnNameArray) { | ||
columnNames += columnNameArray[index]; | ||
if (typeof(valueArray[index]) === 'string') { | ||
values += "'" + valueArray[index] + "'"; | ||
} else { | ||
values += valueArray[index]; | ||
} | ||
if (index != columnNameArray.length - 1) { | ||
columnNames += ","; | ||
values += ","; | ||
} | ||
} | ||
sql += columnNames + ') '+ values + ');'; | ||
this.runSql(sql, callback); | ||
}, | ||
removeIndex: function(indexName, callback) { | ||
@@ -150,0 +180,0 @@ var sql = util.format('DROP INDEX %s', indexName); |
@@ -12,2 +12,31 @@ var util = require('util'); | ||
mapDataType: function(str) { | ||
switch(str) { | ||
case type.STRING: | ||
return 'VARCHAR'; | ||
case type.TEXT: | ||
return 'TEXT'; | ||
case type.INTEGER: | ||
return 'INTEGER'; | ||
case type.DATE_TIME: | ||
return 'DATETIME'; | ||
case type.REAL: | ||
return 'REAL'; | ||
case type.BLOB: | ||
return 'BLOB'; | ||
default: | ||
throw new Error('Invalid data type ' + str); | ||
} | ||
}, | ||
createColumnDef: function(name, spec, options) { | ||
var type = this.mapDataType(spec.type); | ||
var len = spec.length ? util.format('(%s)', spec.length) : ''; | ||
if (type === 'VARCHAR' && len === '') { | ||
len = '(255)'; | ||
} | ||
var constraint = this.createColumnConstraint(spec, options); | ||
return [name, type, len, constraint].join(' '); | ||
}, | ||
createColumnConstraint: function(spec, options) { | ||
@@ -53,2 +82,6 @@ var constraint = []; | ||
removeIndex: function(tableName, indexName, callback) { | ||
var sql = util.format('DROP INDEX %s ON %s', indexName, tableName); | ||
this.runSql(sql, callback); | ||
}, | ||
// renameColumn: function(tableName, oldColumnName, newColumnName, callback) { | ||
@@ -55,0 +88,0 @@ // }, |
@@ -177,3 +177,3 @@ var util = require('util'); | ||
var db = config.db || new pg.Client(config); | ||
callback(null, new PgDriver(db)); | ||
callback(null, new PgDriver(db), db); | ||
}; |
@@ -5,2 +5,3 @@ var fs = require('fs'); | ||
var lpad = require('./util').lpad; | ||
var config = require('./config'); | ||
@@ -7,0 +8,0 @@ function formatPath(name) { |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"engines": { | ||
@@ -44,3 +44,3 @@ "node": ">=0.6.0" | ||
"vows": "~0.6.2", | ||
"db-meta": "~0.3.2" | ||
"db-meta": "~0.4.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "scripts": { |
@@ -321,2 +321,13 @@ # db-migrate | ||
### insert(tableName, columnNameArray, valueArray, callback) | ||
Insert an item into a given column | ||
__Arguments__ | ||
* tableName - table to insert the item into | ||
* columnNameArray - the array existing column names for each item being inserted | ||
* valueArray - the array of values to be inserted into the associated column | ||
* callback(err) - callback that will be invoked once the insert has been completed. | ||
### removeIndex(indexName, callback) | ||
@@ -323,0 +334,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
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
93516
1364
385
1