Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adapters/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function (config, logger) {
return ensureMigrationTableExists().then(function () {
return exec('select * from __migrations__');
}).then(function (rows) {
return rows.map(function (row) { return row.id; });
return rows.map(function (row) { return String(row.id); });
});
},
applyMigration: function applyMigration(migration, sql) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function (config, logger) {
return ensureMigrationTableExists().then(function () {
return exec('select * from __migrations__');
}).then(function (result) {
return result.rows.map(function (row) { return row.id; });
return result.rows.map(function (row) { return String(row.id); });
});
},
applyMigration: function applyMigration(migration, sql) {
Expand Down
2 changes: 1 addition & 1 deletion commands/run-migrations-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getPending(migrationsList, appliedMigrationIds, minMigrationTime) {
var pending = [];
migrationsList.forEach(function (migration) {
var id = migration.match(/^(\d+)/)[0];
if ((!minMigrationTime || id >= minMigrationTime) && !~appliedMigrationIds.indexOf(id) && migration.match(/^\d+\_up.*$/)) {
if ((!minMigrationTime || id >= minMigrationTime) && !appliedMigrationIds.includes(id) && migration.match(/^\d+\_up.*$/)) {
pending.push(migration);
}
});
Expand Down
22 changes: 22 additions & 0 deletions config_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var path = require('path');

module.exports = {
mysql: {
migrationsDir: path.resolve(process.cwd(), 'mysql-migrations'),
adapter: 'mysql',
user: 'root',
host: 'localhost',
db: 'sql_migrations',
password: 'root',
port: 3306
},
postgres: {
migrationsDir: path.resolve(process.cwd(), 'migrations'),
adapter: 'pg',
user: 'postgres',
host: 'localhost',
db: 'sql_migrations',
password: 'postgres',
port: 5432
}
}
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

services:
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=sql_migrations
ports:
- "3306:3306"
postgresql:
image: postgres:9.6
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=sql_migrations
ports:
- "5432:5432"
3 changes: 3 additions & 0 deletions migrate-mysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('./config_test').mysql

require('./').run(config);
11 changes: 2 additions & 9 deletions migrate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
var path = require('path');
const config = require('./config_test').postgres

require('./').run({
migrationsDir: path.resolve(process.cwd, 'migrations'),
user: 'dabramov',
host: 'localhost',
db: 'sql_migrations',
password: 'pgpassword',
port: 5432
});
require('./').run(config);
2 changes: 1 addition & 1 deletion migrations/1415848008750_up_migrate.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table "testtesttest" (id int);
create table if not exists "testtesttest" (id int);
Empty file.
1 change: 1 addition & 0 deletions mysql-migrations/1415847181182_up_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 2;
1 change: 1 addition & 0 deletions mysql-migrations/1415848008750_down_migrate.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop table "testtesttest";
1 change: 1 addition & 0 deletions mysql-migrations/1415848008750_up_migrate.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table if not exists testtesttest (id int);
Empty file.
1 change: 1 addition & 0 deletions mysql-migrations/1415856540610_up_test2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1;
Empty file.
4 changes: 4 additions & 0 deletions mysql-migrations/1562632680494_up_test3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create procedure sp_test_echo()
begin
select "hello world";
end;
Loading