Skip to content

Commit

Permalink
fix: resolve postgres array enum migration issue
Browse files Browse the repository at this point in the history
Closes: typeorm#4350
  • Loading branch information
TheNoim committed Oct 18, 2020
1 parent 0956ffc commit fd3e6a1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2059,9 +2059,27 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
}
const result = await this.query(`SELECT "udt_schema", "udt_name" ` +
`FROM "information_schema"."columns" WHERE "table_schema" = '${schema}' AND "table_name" = '${name}' AND "column_name"='${column.name}'`);

let udtName = result[0]["udt_name"];

// You can not modify the array type. You need to edit the enum itself.
if (column.isArray) {
// Find the information about the array type
const typeResult = await this.query(`select "typelem" from pg_type where "typname" = '${udtName}';`);

const typelem = typeResult[0]["typelem"];
// Get with the oid of the enum array type the enum type
const baseTypeNameResult = await this.query(`select "typname" from pg_type where oid = ${typelem}`);

const baseTypeName = baseTypeNameResult[0]["typname"];

// Replace the udtName with the enum type
udtName = baseTypeName;
}

return {
enumTypeSchema: result[0]["udt_schema"],
enumTypeName: result[0]["udt_name"]
enumTypeName: udtName
};
}

Expand Down

0 comments on commit fd3e6a1

Please sign in to comment.