环境
-
Knex版本:knex@0.16.3
-
数据库+版本:MySQL5.7.24
-
操作系统:Linux(Manjaro)
缺陷
ava
. 众所周知,
艾娃
为每个测试文件生成不同的节点进程。
为了隔离测试,我需要重新创建数据库并在所有测试文件中运行迁移。我开始引导并得到以下脚本:
import test from 'ava';
import cuid from 'cuid';
import knexFactory from 'knex';
import knexFile from './knexfile';
const knex = knexFactory(knexFile.development);
test.before(async t => {
const schemaName = `foo_${cuid()}`;
await knex.raw(`CREATE SCHEMA ${schemaName}`);
try {
await knex.migrate.latest({ schemaName });;
} catch (err) {
}
Object.assign(t.context, { schemaName });
});
test.after.always(async t => {
const { schemaName } = t.context;
await knex.raw(`DROP SCHEMA ${schemaName}`);
});
test('foo', () => {})
迁移文件“2019020510315\u create\u users”_表.js“失败
迁移失败,出现错误:create table
users
(
id
int unsigned not null自动递增主键,
email
瓦尔查尔(255),
password
文本)-表“users”已存在
.migrate.latest()
呼叫正在忽略其
schemaName
参数中定义的配置运行
knexfile.js
迁移文件非常简单:
exports.up = function(knex, Promise) {
return knex.schema.createTable('users', table => {
table.increments();
table.string('email');
table.text('password');
})
};
exports.down = function(knex, Promise) {
return knex.schema.dropTable('users');
};