Skip to content
Merged
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
14 changes: 13 additions & 1 deletion src/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { _execSQL } = require('./core');
const { _render } = require('@axiosleo/cli-tool/src/helper/str');
const { _foreach } = require('@axiosleo/cli-tool/src/helper/cmd');
const { _assign } = require('@axiosleo/cli-tool/src/helper/obj');
const { TransactionHandler } = require('..');
const { TransactionHandler } = require('./transaction');
const { ManageSQLBuilder, Builder } = require('./builder');

const migrationColumns = [
Expand Down Expand Up @@ -81,7 +81,13 @@ async function init(context) {
context.pool = conn;

handler = new QueryHandler(conn);
context.items = {};
if (await handler.existTable(context.task_key, database)) {
printer.yellow('table ' + context.task_key + ' already exists').println();
const items = await handler.table(context.task_key).select();
items.forEach(item => {
context.items[item.filename] = true;
});
conn.end();
return;
}
Expand Down Expand Up @@ -321,6 +327,12 @@ async function run(context) {
const { files } = context;
const queries = {};
await _foreach(files, async (file) => {
if (context.action === 'up' && context.items[file]) {
printer.yellow(`Migration file "${file}" has been migrated.`).println();
return;
} else if (context.action === 'down' && !context.items[file]) {
return;
}
const scriptPath = path.join(context.config.dir, file);
const script = require(scriptPath);
queries[file] = [];
Expand Down