小编chm*_*max的帖子

Knex和Postgresql更改列类型

现在我这样做是为了将列类型从字符串更改为枚举.有没有其他方法可以做到这一点?

是否可以将它用作knex.raw来形成这样的查询?

CREATE TYPE type AS ENUM ('disabled', 'include', 'exclude');
ALTER TABLE test_table ALTER COLUMN test_col DROP DEFAULT;
ALTER TABLE test_table ALTER COLUMN test_col TYPE logic USING(test_col::type), ALTER COLUMN test_col SET DEFAULT 'disabled'::logic;


       return schema
        .table('offers', function (table) {
            cols.forEach(function (column) {
                table.renameColumn(column, column + '_old');
            });

        }).then(function () {

            var schema = knex.schema;

            return schema.table('offers', function (table) {
                cols.forEach(function (column) {
                    table.enum(column, ['disabled', 'include', 'exclude']).defaultTo('disabled');
                });
            });

        }).then(function () {
            return knex.select('*').from('offers');
        }).then(function (rows) {

            return Promise.map(rows, function (row) …
Run Code Online (Sandbox Code Playgroud)

postgresql knex.js

7
推荐指数
1
解决办法
2014
查看次数

标签 统计

knex.js ×1

postgresql ×1