db-migrate
Advanced tools
Comparing version 0.6.4 to 0.7.0
@@ -216,1 +216,9 @@ ## 0.1.0 | ||
## 0.7.0 (2014-08-01) | ||
Improvement: | ||
- Externalize db configuration for tests #180 (via @dlaxar) | ||
- Tightening up some js syntax #179 (via @paulomcnally) | ||
- Change down migrations to execute in order they were run #178 (via @ajkerr) | ||
- addForeignKey and removeForeignKey added to mysql #174 (via @JohanObrink) | ||
- Add ability to use .env file for config if present #170 (via @bvalosek) |
@@ -8,13 +8,15 @@ Without pull requests from generous people like you, this project | ||
2. Run the tests. Pull requests without tests are much less likely to be | ||
2. Copy the test/db.config.example.json to test/db.config.json | ||
3. Run the tests. Pull requests without tests are much less likely to be | ||
merged, and it's great to know you're starting with a clean slate: `npm test`. | ||
Be sure to check the README for setting up your test databases first. | ||
3. Add a test for your change. Refactoring and documentation changes | ||
4. Add a test for your change. Refactoring and documentation changes | ||
require no new tests. If you are adding functionality or fixing a bug, | ||
please include a test. | ||
4. Make the test pass. | ||
5. Make the test pass. | ||
5. Push to your fork and submit a pull request. | ||
6. Push to your fork and submit a pull request. | ||
@@ -21,0 +23,0 @@ At this point you're waiting on me. In a perfect world I'd commit to |
@@ -210,2 +210,10 @@ var util = require('util'); | ||
addForeignKey: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
removeForeignKey: function() { | ||
throw new Error('not implemented'); | ||
}, | ||
normalizeColumnSpec: function(obj) { | ||
@@ -212,0 +220,0 @@ if (typeof(obj) === 'string') { |
@@ -239,2 +239,24 @@ var util = require('util'); | ||
addForeignKey: function(tableName, referencedTableName, keyName, fieldMapping, rules, callback) { | ||
if(arguments.length === 5 && typeof(rules) === 'function') { | ||
callback = rules; | ||
rules = {}; | ||
} | ||
var columns = Object.keys(fieldMapping); | ||
var referencedColumns = columns.map(function (key) { return fieldMapping[key]; }); | ||
var sql = util.format('ALTER TABLE `%s` ADD CONSTRAINT `%s` FOREIGN KEY (%s) REFERENCES `%s` (%s) ON DELETE %s ON UPDATE %s', | ||
tableName, keyName, columns, referencedTableName, referencedColumns, rules.onDelete || 'NO ACTION', rules.onUpdate || 'NO ACTION'); | ||
this.runSql(sql, callback); | ||
}, | ||
removeForeignKey: function(tableName, keyName, callback) { | ||
var sql = util.format('ALTER TABLE `%s` DROP FOREIGN KEY `%s`', tableName, keyName); | ||
this.runSql(sql, function () { | ||
sql = util.format('ALTER TABLE `%s` DROP INDEX `%s`', tableName, keyName); | ||
this.runSql(sql, function () { | ||
callback(); | ||
}); | ||
}.bind(this)); | ||
}, | ||
runSql: function() { | ||
@@ -241,0 +263,0 @@ var args = this._makeParamArgs(arguments); |
@@ -137,3 +137,3 @@ var fs = require('fs'); | ||
log.verbose('loading migrations from database'); | ||
driver.all('SELECT * FROM migrations ORDER BY name DESC', function(err, dbResults) { | ||
driver.all('SELECT * FROM migrations ORDER BY run_on DESC, name DESC', function(err, dbResults) { | ||
if (err) { callback(err); return; } | ||
@@ -140,0 +140,0 @@ var migrations = dbResults.map(function(result) { |
@@ -15,11 +15,2 @@ var async = require('async'); | ||
function isIncludedInDown(migration, destination) { | ||
if(!destination) { | ||
return true; | ||
} | ||
var migrationTest = migration.name.substring(0, Math.min(migration.name.length, destination.length)); | ||
var destinationTest = destination.substring(0, Math.min(migration.name.length, destination.length)); | ||
return migrationTest >= destinationTest; | ||
} | ||
function filterUp(allMigrations, completedMigrations, destination, count) { | ||
@@ -43,8 +34,4 @@ var sortFn = function(a, b) { | ||
function filterDown(completedMigrations, destination, count) { | ||
return completedMigrations | ||
.filter(function(completedMigration) { | ||
return isIncludedInDown(completedMigration, destination); | ||
}) | ||
.slice(0, count); | ||
function filterDown(completedMigrations, count) { | ||
return completedMigrations.slice(0, count); | ||
} | ||
@@ -99,14 +86,6 @@ | ||
} else { | ||
this.downToBy(funcOrOpts.destination, funcOrOpts.count, callback); | ||
this.downToBy(funcOrOpts.count, callback); | ||
} | ||
}, | ||
upBy: function(count, callback) { | ||
this.upToBy('99999999999999', count, callback); | ||
}, | ||
upTo: function(partialName, callback) { | ||
this.upToBy(partialName, Number.MAX_VALUE, callback); | ||
}, | ||
upToBy: function(partialName, count, callback) { | ||
@@ -140,11 +119,3 @@ var self = this; | ||
downBy: function(count, callback) { | ||
this.downToBy('00000000000000', count, callback); | ||
}, | ||
downTo: function(partialName, callback) { | ||
this.downToBy(partialName, Number.MAX_VALUE, callback); | ||
}, | ||
downToBy: function(partialName, count, callback) { | ||
downToBy: function(count, callback) { | ||
var self = this; | ||
@@ -154,3 +125,3 @@ Migration.loadFromDatabase(self.migrationsDir, self.driver, function(err, completedMigrations) { | ||
var toRun = filterDown(completedMigrations, partialName, count); | ||
var toRun = filterDown(completedMigrations, count); | ||
@@ -157,0 +128,0 @@ if (toRun.length === 0) { |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.6.4", | ||
"version": "0.7.0", | ||
"engines": { | ||
@@ -34,3 +34,4 @@ "node": ">=0.6.0" | ||
"pkginfo": "~0.3.0", | ||
"parse-database-url": "~0.2.0" | ||
"parse-database-url": "~0.2.0", | ||
"dotenv": "~0.2.8" | ||
}, | ||
@@ -37,0 +38,0 @@ "devDependencies": { |
@@ -20,2 +20,5 @@ # db-migrate | ||
Down migrations are run in reverse run order, so migrationName is ignored for down migrations. | ||
Use the --count option to control how many down migrations are run (default is 1). | ||
Options: | ||
@@ -416,2 +419,5 @@ --env, -e The environment to run the migrations under. [default: "dev"] | ||
You will also need to copy `test/db.config.example.json` to `test/db.config.json` | ||
and adjust appropriate to setup configuration for your database instances. | ||
## License | ||
@@ -418,0 +424,0 @@ |
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
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
87517
1708
445
8
+ Addeddotenv@~0.2.8
+ Addeddotenv@0.2.8(transitive)