Fix #398, #410, escape field with enum / postgres

This commit is contained in:
Tim Griesser 2014-08-14 15:44:46 -04:00
parent 0b1af71ac3
commit a768c7881b
3 changed files with 3 additions and 3 deletions

View File

@ -34,7 +34,7 @@ ColumnCompiler_PG.prototype.bool = 'boolean';
// Create the column definition for an enum type.
// Using method "2" here: http://stackoverflow.com/a/10984951/525714
ColumnCompiler_PG.prototype.enu = function(allowed) {
return 'text check (' + this.args[0] + " in ('" + allowed.join("', '") + "'))";
return 'text check (' + this.formatter.wrap(this.args[0]) + " in ('" + allowed.join("', '") + "'))";
};
ColumnCompiler_PG.prototype.double = 'double precision',

View File

@ -120,7 +120,7 @@ module.exports = function(knex) {
table.uuid('uuid').notNull();
}).testSql(function(tester) {
tester('mysql', ['create table `datatype_test` (`enum_value` enum(\'a\', \'b\', \'c\'), `uuid` char(36) not null) default character set utf8']);
tester('postgresql', ['create table "datatype_test" ("enum_value" text check (enum_value in (\'a\', \'b\', \'c\')), "uuid" uuid not null)']);
tester('postgresql', ['create table "datatype_test" ("enum_value" text check ("enum_value" in (\'a\', \'b\', \'c\')), "uuid" uuid not null)']);
tester('sqlite3', ['create table "datatype_test" ("enum_value" varchar, "uuid" char(36) not null)']);
tester('oracle', ['create table "datatype_test" ("enum_value" varchar2(1) check ("enum_value" in (\'a\', \'b\', \'c\')), "uuid" char(36) not null)']);
});

View File

@ -352,7 +352,7 @@ module.exports = function(client) {
table.enum('foo', ['bar', 'baz']);
}).toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal('alter table "users" add column "foo" text check (foo in (\'bar\', \'baz\'))');
expect(tableSql[0].sql).to.equal('alter table "users" add column "foo" text check ("foo" in (\'bar\', \'baz\'))');
});
it("adding date", function() {