不要怂,就是干,撸起袖子干!

Commit 23652061 by Varga Zsolt Committed by Sushant

fix(postgresql): search path with datatypes that use dynamic oids (#9148)

1 parent 78a1fb6c
...@@ -208,7 +208,16 @@ class ConnectionManager extends AbstractConnectionManager { ...@@ -208,7 +208,16 @@ class ConnectionManager extends AbstractConnectionManager {
return (connection || this.sequelize).query( return (connection || this.sequelize).query(
"SELECT typname, typtype, oid, typarray FROM pg_type WHERE (typtype = 'b' AND typname IN ('hstore', 'geometry', 'geography')) OR (typtype = 'e')" "SELECT typname, typtype, oid, typarray FROM pg_type WHERE (typtype = 'b' AND typname IN ('hstore', 'geometry', 'geography')) OR (typtype = 'e')"
).then(results => { ).then(results => {
const result = Array.isArray(results) ? results.pop() : results; let result = Array.isArray(results) ? results.pop() : results;
// When searchPath is prepended then two statements are executed and the result is
// an array of those two statements. First one is the SET search_path and second is
// the SELECT query result.
if (Array.isArray(result)) {
if (result[0].command === 'SET') {
result = result.pop();
}
}
// Reset OID mapping for dynamic type // Reset OID mapping for dynamic type
[ [
......
...@@ -18,7 +18,6 @@ let locationId; ...@@ -18,7 +18,6 @@ let locationId;
describe(Support.getTestDialectTeaser('Model'), () => { describe(Support.getTestDialectTeaser('Model'), () => {
if (current.dialect.supports.searchPath) { if (current.dialect.supports.searchPath) {
describe('SEARCH PATH', () => { describe('SEARCH PATH', () => {
before(function() { before(function() {
this.Restaurant = current.define('restaurant', { this.Restaurant = current.define('restaurant', {
...@@ -27,7 +26,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -27,7 +26,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}, },
{tableName: 'restaurants'}); {tableName: 'restaurants'});
this.Location = current.define('location', { this.Location = current.define('location', {
name: DataTypes.STRING name: DataTypes.STRING,
type: DataTypes.ENUM('a', 'b')
}, },
{tableName: 'locations'}); {tableName: 'locations'});
this.Employee = current.define('employee', { this.Employee = current.define('employee', {
...@@ -51,7 +51,6 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -51,7 +51,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
beforeEach('build restaurant tables', function() { beforeEach('build restaurant tables', function() {
const Restaurant = this.Restaurant; const Restaurant = this.Restaurant;
return current.createSchema('schema_one').then(() => { return current.createSchema('schema_one').then(() => {
...@@ -71,6 +70,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -71,6 +70,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
describe('enum case', () => {
it('able to refresh enum when searchPath is used', function () {
return this.Location.sync({ force: true });
});
});
describe('Add data via model.create, retrieve via model.findOne', () => { describe('Add data via model.create, retrieve via model.findOne', () => {
it('should be able to insert data into the table in schema_one using create', function() { it('should be able to insert data into the table in schema_one using create', function() {
const Restaurant = this.Restaurant; const Restaurant = this.Restaurant;
...@@ -292,7 +297,6 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -292,7 +297,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
it('should be able to insert and retrieve associated data into the table in schema_two', function() { it('should be able to insert and retrieve associated data into the table in schema_two', function() {
const Restaurant = this.Restaurant; const Restaurant = this.Restaurant;
const Location = this.Location; const Location = this.Location;
...@@ -379,7 +383,6 @@ describe(Support.getTestDialectTeaser('Model'), () => { ...@@ -379,7 +383,6 @@ describe(Support.getTestDialectTeaser('Model'), () => {
}); });
}); });
it('should be able to insert and retrieve associated data into the table in schema_two', function() { it('should be able to insert and retrieve associated data into the table in schema_two', function() {
const Restaurant = this.Restaurant; const Restaurant = this.Restaurant;
const Employee = this.Employee; const Employee = this.Employee;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!