나는 거의 모든 것에 익숙하지 않습니다. 단일 마이그레이션 파일을 사용하여 MySQL 데이터베이스 (20 개 테이블)의 모든 테이블을 만들려고했습니다. 틀림없이Knex MySQL Migration "처리되지 않은 거부 오류 : 트랜잭션 쿼리가 이미 완료되었습니다"
Unhandled rejection Error: Transaction query already complete, run with DEBUG=knex:tx for more info
내가하지 않아도 :
exports.up = function(knex, Promise) {
function createTable1() {
return knex.schema.createTableIfNotExists('Table1', (t) => {
t.increments('id').primary();
t.string('col_1', 48).unique().notNullable();
t.timestamps(true, true);
}).catch((e) => console.log(e));
}
function createTable2() {
return knex.schema.createTableIfNotExists('Table2', (t) => {
t.increments('id').primary();
t.string('col_1', 48).unique().notNullable();
t.integer('someId').unsigned().references('Table1.id')
t.timestamps(true, true);
}).catch((e) => console.log(e));
}
function createTable3() {
return knex.schema.createTableIfNotExists('Table3', (t) => {
t.increments('id').primary();
t.string('col_1', 48).unique().notNullable();
t.integer('someId').unsigned().references('Table1.id')
t.integer('someOtherId').unsigned().references('Table2.id')
t.timestamps(true, true);
}).catch((e) => console.log(e));
}
... //similar functions for all 20 tables
return Promise.all([
createTable1()
.then(createTable2())
.then(createTable3())
...
.then(createTable20())
.catch((e) => console.log(e.sql))
]);
}
exports.down = function(knex, Promise) {
return knex.schema.dropTable('Table1')
.then(knex.schema.dropTable('Table2'))
.then(knex.schema.dropTable('Table3'))
...
.then(knex.schema.dropTable('Table20'))
.catch((e) => console.log(e.sql))
};
나는 하나의 트랜잭션 마이그레이션 실행하지만, 다음과 같은 오류가 발생
에서 SQL 쿼리를 모두 실행 knex 예상 약속을 올바르게 사용하는 방법에 대한 확고한 이해와 나는 Promise.all 블록이 반드시 & execut 같은 순서로 SQL 쿼리를 처리 할 수 있습니까? 각 테이블에 대해 별도의 마이그레이션 파일을 만드는 것이 더 합리적입니까?
> 각 테이블에 대해 별도의 마이그레이션 파일을 만드는 것이 더 중요합니까? 나는 그것을하는 것이 더 일반적이라고 생각합니다. – langitbiru