Skip to content

Commit

Permalink
fix: support postgres column with varchar datatype and uuid_generate_…
Browse files Browse the repository at this point in the history
…v4() default

Closes: typeorm#9063
  • Loading branch information
knarfchan committed Jun 2, 2022
1 parent bbdc20f commit ff8761b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/driver/postgres/PostgresQueryRunner.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ObjectLiteral } from "../../common/ObjectLiteral"
import { TypeORMError } from "../../error"
import { QueryFailedError } from "../../error/QueryFailedError"
import { QueryRunnerAlreadyReleasedError } from "../../error/QueryRunnerAlreadyReleasedError"
import { TransactionNotStartedError } from "../../error/TransactionNotStartedError"
import { ColumnType } from "../types/ColumnTypes"
import { ReadStream } from "../../platform/PlatformTools"
import { BaseQueryRunner } from "../../query-runner/BaseQueryRunner"
import { QueryResult } from "../../query-runner/QueryResult"
import { QueryRunner } from "../../query-runner/QueryRunner"
import { TableIndexOptions } from "../../schema-builder/options/TableIndexOptions"
import { Table } from "../../schema-builder/table/Table"
Expand All @@ -16,16 +17,15 @@ import { TableIndex } from "../../schema-builder/table/TableIndex"
import { TableUnique } from "../../schema-builder/table/TableUnique"
import { View } from "../../schema-builder/view/View"
import { Broadcaster } from "../../subscriber/Broadcaster"
import { InstanceChecker } from "../../util/InstanceChecker"
import { OrmUtils } from "../../util/OrmUtils"
import { VersionUtils } from "../../util/VersionUtils"
import { Query } from "../Query"
import { ColumnType } from "../types/ColumnTypes"
import { IsolationLevel } from "../types/IsolationLevel"
import { PostgresDriver } from "./PostgresDriver"
import { ReplicationMode } from "../types/ReplicationMode"
import { VersionUtils } from "../../util/VersionUtils"
import { TypeORMError } from "../../error"
import { QueryResult } from "../../query-runner/QueryResult"
import { MetadataTableType } from "../types/MetadataTableType"
import { InstanceChecker } from "../../util/InstanceChecker"
import { ReplicationMode } from "../types/ReplicationMode"
import { PostgresDriver } from "./PostgresDriver"

/**
* Runs queries on a single postgres database connection.
Expand Down Expand Up @@ -3599,8 +3599,13 @@ export class PostgresQueryRunner
dbColumn["column_default"],
)
) {
tableColumn.isGenerated = true
tableColumn.generationStrategy = "uuid"
if (dbColumn["data_type"] === "uuid") {
tableColumn.isGenerated = true
tableColumn.generationStrategy = "uuid"
} else {
tableColumn.default =
dbColumn["column_default"]
}
} else if (
dbColumn["column_default"] === "now()" ||
dbColumn["column_default"].indexOf(
Expand Down

0 comments on commit ff8761b

Please sign in to comment.