JSK*_*JSK 1 migration postgresql database-migration knex.js
我正在尝试更改表中的列以将 knex 枚举修改为本机类型,以利用 Postgres 的类型系统,当我执行迁移时,我收到此错误类型"request_type" already exists,知道这里发生了什么吗?
export async function up(knex: Knex): Promise<any> {
return knex.schema.alterTable('appointments', table => {
table.enu('type', ['video', 'physical'], { useNative: true, enumName: 'request_type' }).alter();
});
}
export async function down(knex: Knex): Promise<any> {
return knex.schema
.alterTable('appointments', table => {
table.dropColumn('type');
})
.then(() => knex.raw('CREATE TYPE request_type AS ENUM("video", "physical")'))
.then(() => knex.raw('drop type request_type'));
}
Run Code Online (Sandbox Code Playgroud)
看起来 knex 中存在一个错误,导致在更改此类列时创建类型查询被添加两次。
\n\nhttps://runkit.com/embed/xqtl8p2knhi8
\n\nconst Knex = require(\'knex\');\n\nconst knex = Knex({\n client: \'pg\',\n});\n\nknex.schema.alterTable(\'appointments\', table => {\n table.enu(\'type\', [\'video\', \'physical\'], { useNative: true, enumName: \'request_type\' }).alter();\n}).toSQL()\n\n/*\n Creates SQL:\n\n0: Object {bindings: [], sql: "create type \\"request_type\\" as enum (\'video\', \'physical\')"}\n1: Object {bindings: [], sql: "create type \\"request_type\\" as enum (\'video\', \'physical\')"}\n2: Object {bindings: [], sql: "alter table \\"appointments\\" alter column \\"type\\" drop default"}\n3: Object {bindings: [], sql: "alter table \\"appointments\\" alter column \\"type\\" drop not null"}\n4: Object {bindings: [], \xe2\x80\xa6}\n*/\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2066 次 |
| 最近记录: |