Skip to content

Commit d3e98a8

Browse files
committed
refactor: disconnect create from connect
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent 11b918a commit d3e98a8

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

connect.js

-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var log = require('db-migrate-shared').log;
1111
exports.connect = function (config, PassedClass, callback) {
1212
var internals = {};
1313
var prefix = 'migration';
14-
var migrationsDir;
1514
if (config.config) {
1615
prefix = config.prefix || prefix;
1716
internals = config.internals;
@@ -191,14 +190,3 @@ function migrationFiles (
191190
}
192191
});
193192
}
194-
195-
exports.createMigration = function (migration, callback) {
196-
migration.write(function (err) {
197-
if (err) {
198-
callback(err);
199-
return;
200-
}
201-
202-
callback(null, migration);
203-
});
204-
};

lib/commands/create-migration.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function executeCreateMigration (internals, config, callback) {
4242
}
4343

4444
createMigrationDir(migrationsDir, function (err) {
45-
const index = require('../../connect');
4645
const Migration = require('../template.js');
4746

4847
if (err) {
@@ -91,7 +90,7 @@ function executeCreateMigration (internals, config, callback) {
9190
internals.runTimestamp,
9291
templateType
9392
);
94-
index.createMigration(migration, function (err, migration) {
93+
migration.write(function (err) {
9594
if (_assert(err, callback)) {
9695
log.info(util.format('Created migration at %s', migration.file.path));
9796
if (shouldCreateSqlFiles(internals, config)) {
@@ -128,7 +127,6 @@ function createSqlFiles (internals, config, callback) {
128127

129128
const sqlDir = migrationsDir + '/sqls';
130129
createMigrationDir(sqlDir, function (err) {
131-
const index = require('../../connect');
132130
const Migration = require('../template.js');
133131

134132
if (err) {
@@ -148,12 +146,12 @@ function createSqlFiles (internals, config, callback) {
148146
internals.runTimestamp,
149147
templateTypeDefaultSQL
150148
);
151-
index.createMigration(migrationUpSQL, function (err, migration) {
149+
migrationUpSQL.write(function (err) {
152150
if (_assert(err, callback)) {
153151
log.info(
154152
util.format(
155153
'Created migration up sql file at %s',
156-
migration.file.path
154+
migrationUpSQL.file.path
157155
)
158156
);
159157

@@ -163,12 +161,12 @@ function createSqlFiles (internals, config, callback) {
163161
internals.runTimestamp,
164162
templateTypeDefaultSQL
165163
);
166-
index.createMigration(migrationDownSQL, function (err, migration) {
164+
migrationDownSQL.write(function (err) {
167165
if (_assert(err, callback)) {
168166
log.info(
169167
util.format(
170168
'Created migration down sql file at %s',
171-
migration.file.path
169+
migrationDownSQL.file.path
172170
)
173171
);
174172
if (typeof callback === 'function') callback();

0 commit comments

Comments
 (0)