Socket
Socket
Sign inDemoInstall

db-migrate

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-migrate - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

7

CHANGELOG.md

@@ -77,1 +77,8 @@ ## 0.1.0

- Fix randomly occuring migration sorting error on empty db #51
## 0.2.6
Fix:
- Fix db.removeIndex for MySQL #42 (via @aprobus)
- Workaround for node-mysql bug felixge/node-mysql#289 #54 (via
@aprobus)

13

lib/driver/base.js

@@ -176,3 +176,10 @@ var util = require('util');

removeIndex: function(indexName, callback) {
removeIndex: function(tableName, indexName, callback) {
if (arguments.length === 2 && typeof(indexName) === 'function') {
callback = indexName;
indexName = tableName;
} else if (arguments.length === 1 && typeof(tableName) === 'string') {
indexName = tableName;
}
var sql = util.format('DROP INDEX %s', indexName);

@@ -190,2 +197,6 @@ this.runSql(sql, callback);

addMigrationRecord: function (name, callback) {
this.runSql('INSERT INTO migrations (name, run_on) VALUES (?, ?)', [name, new Date()], callback);
},
startMigration: function(cb){cb()},

@@ -192,0 +203,0 @@ endMigration: function(cb){cb()},

15

lib/driver/index.js

@@ -6,12 +6,7 @@ exports.connect = function(config, callback) {

if (typeof(config.driver) === 'string') {
var driver = require('./' + config.driver);
driver.connect(config, function(err, driverInstance) {
if (err) { callback(err); return; }
callback(null, driverInstance);
});
} else {
// the user has already created the driver
callback(null, config.driver);
}
var driver = require('./' + config.driver);
driver.connect(config, function(err, db) {
if (err) { callback(err); return; }
callback(null, db);
});
};
var util = require('util');
var moment = require('moment');
var mysql = require('mysql');

@@ -82,2 +83,12 @@ var Base = require('./base');

removeIndex: function(tableName, indexName, callback) {
// tableName is optional for other drivers, but required for mySql. So, check the args to ensure they are valid
if (arguments.length === 2 && typeof(indexName) === 'function') {
callback = indexName;
process.nextTick(function () {
callback(new Error('Illegal arguments, must provide "tableName" and "indexName"'));
});
return;
}
var sql = util.format('DROP INDEX %s ON %s', indexName, tableName);

@@ -95,2 +106,7 @@ this.runSql(sql, callback);

addMigrationRecord: function (name, callback) {
var formattedDate = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
this.runSql('INSERT INTO migrations (name, run_on) VALUES (?, ?)', [name, formattedDate], callback);
},
runSql: function() {

@@ -97,0 +113,0 @@ this.connection.query.apply(this.connection, arguments);

@@ -70,3 +70,3 @@ var async = require('async');

}
this.driver.runSql('INSERT INTO migrations (name, run_on) VALUES (?, ?)', [migration.name, new Date()], onComplete);
this.driver.addMigrationRecord(migration.name, onComplete);
},

@@ -73,0 +73,0 @@

@@ -14,3 +14,3 @@ {

],
"version": "0.2.5",
"version": "0.2.6",
"engines": {

@@ -27,2 +27,6 @@ "node": ">=0.6.0"

"email": "joe.ferner@nearinfinity.com"
},
{
"name": "Aaron Probus",
"email": "aaron.probus@nearinfinity.com"
}

@@ -42,3 +46,4 @@ ],

"semver": "~1.0.14",
"mkdirp": "~0.3.4"
"mkdirp": "~0.3.4",
"moment": "~1.7.2"
},

@@ -45,0 +50,0 @@ "devDependencies": {

@@ -170,3 +170,3 @@ # db-migrate

db-migrate supports the concept of environments. For example, you might have a dev, test, and prod environment where you need to run the migrations at different times. By default, environment settings are loaded from a database.json file like the one shown below:
db-migrate supports the concept of environments. For example, you might have a dev, test, and prod environment where you need to run the migrations at different times. Environment settings are loaded from a database.json file like the one shown below:

@@ -190,3 +190,3 @@ ```javascript

},
"pg": {

@@ -202,40 +202,4 @@ "driver": "pg",

Your database configuration can also be specified using a JavaScript
file. This is helpful when you'd like to manually instantiate and
configure the database driver. Below is an example of what a
JavaScript-based configuration file would need to look like.
You can pass the -e or --env option to db-migrate to select the environment you want to run migrations against. The --config option can be used to specify the path to your database.json file if it's not in the current working directory.
```javascript
var mysqlDriver = require('db-migrate/lib/driver/mysql');
var mysql = require('mysql');
var pgDriver = require('db-migrate/lib/driver/pg');
var pg = require('pg');
var sqlite3Driver = require('db-migrate/lib/driver/sqlite3');
var sqlite3 = require('sqlite3');
var sqlite3Mode = sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE;
module.exports = {
dev: {
driver: new sqlite3.Database('~/dev.db', mode);
},
test: {
driver: new sqlite3.Database(':memory:', mode);
},
prod: {
driver: new mysql.createClient({
"user": "root",
"password": "root"
})
},
pg: {
driver:
}
};
```
You can pass the -e or --env option to db-migrate to select the environment you want to run migrations against. The --config option can be used to specify the path to your database config file if it's not in the current working directory.
db-migrate up --config config/database.json -e prod

@@ -385,3 +349,3 @@

### removeIndex(indexName, callback)
### removeIndex([tableName], indexName, callback)

@@ -392,2 +356,3 @@ Remove an index

* tableName - name of the table that has the index (Required for mySql)
* indexName - the name of the index

@@ -394,0 +359,0 @@ * callback(err) - callback that will be invoked after removing the index

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc