Skip to content

Commit

Permalink
Fix typeorm#3009 user newer extension for postgress UUID gen.
Browse files Browse the repository at this point in the history
New extension does not support Old postgres versions: 9.2 / 9.1 / 9.0 / 8.4 / 8.3

Fixed test
  • Loading branch information
Gints Polis committed Nov 4, 2018
1 parent c56e605 commit acd1bec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/driver/postgres/PostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ export class PostgresDriver implements Driver {
if (err) return fail(err);
if (hasUuidColumns)
try {
await this.executeQuery(connection, `CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
await this.executeQuery(connection, `CREATE EXTENSION IF NOT EXISTS "pgcrypto"`);
} catch (_) {
logger.log("warn", "At least one of the entities has uuid column, but the 'uuid-ossp' extension cannot be installed automatically. Please install it manually using superuser rights");
logger.log("warn", "At least one of the entities has uuid column, but the 'pgcrypto' extension cannot be installed automatically. Please install it manually using superuser rights");
}
if (hasCitextColumns)
try {
Expand Down
2 changes: 1 addition & 1 deletion src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
if (column.default !== undefined && column.default !== null)
c += " DEFAULT " + column.default;
if (column.isGenerated && column.generationStrategy === "uuid" && !column.default)
c += " DEFAULT uuid_generate_v4()";
c += " DEFAULT gen_random_uuid()";

return c;
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/schema-builder/change-column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe("schema builder > change column", () => {
const queryRunner = connection.createQueryRunner();

if (connection.driver instanceof PostgresDriver)
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "pgcrypto"`);

const postMetadata = connection.getMetadata(Post);
const idColumn = postMetadata.findColumnWithPropertyName("id")!;
Expand Down

0 comments on commit acd1bec

Please sign in to comment.