Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4790 from prisma/IntrospectionShouldNotFailOnUnkn…
Browse files Browse the repository at this point in the history
…ownTypes

Introspection should not fail on types Prisma can't handle at the moment
  • Loading branch information
do4gr authored Aug 8, 2019
2 parents 71eaea8 + 3df4b5b commit cdb8ca6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ trait DatabaseInspectorBase extends DatabaseInspector {
introspectedIndexes <- indexes(schema, table)
sequences <- getSequences(schema, table)
} yield {
val columns = introspectedColumns.map { col =>

val columnsPrismaCanHandle = introspectedColumns.filter { case column => typeIdentifierForTypeName(column.udtName).isDefined }

val columns = columnsPrismaCanHandle.map { col =>
// this needs to be extended further in the future if we support arbitrary SQL types
val typeIdentifier = typeIdentifierForTypeName(col.udtName).getOrElse {
sys.error(s"Encountered unknown SQL type ${col.udtName} with column ${col.name}. $col")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ case class PostgresDatabaseInspector(db: SlickDatabase)(implicit val ec: Executi
override protected def typeIdentifierForTypeName(typeName: String): Option[TypeIdentifier.ScalarTypeIdentifier] = {
// https://www.postgresql.org/docs/9.5/datatype.html
typeName match {
case "bool" => Some(TypeIdentifier.Boolean)
case _ if typeName.contains("char") => Some(TypeIdentifier.String)
case _ if typeName.contains("text") => Some(TypeIdentifier.String)
case _ if typeName.contains("int") => Some(TypeIdentifier.Int)
case _ if typeName.contains("serial") => Some(TypeIdentifier.Int)
case "numeric" | "decimal" | "real" => Some(TypeIdentifier.Float)
case "timestamp" => Some(TypeIdentifier.DateTime)
case "uuid" => Some(TypeIdentifier.UUID)
case _ => None
case "bool" => Some(TypeIdentifier.Boolean)
case _ if typeName.contains("char") => Some(TypeIdentifier.String)
case _ if typeName.contains("text") => Some(TypeIdentifier.String)
case _ if typeName.contains("int") => Some(TypeIdentifier.Int)
case _ if typeName.contains("serial") => Some(TypeIdentifier.Int)
case "numeric" | "decimal" | "real" | "float4" | "double precision" | "float8" => Some(TypeIdentifier.Float)
case "timestamp" => Some(TypeIdentifier.DateTime)
case "uuid" => Some(TypeIdentifier.UUID)
case _ => None
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,36 @@ class ExistingDatabasesSpec extends WordSpecLike with Matchers with PassiveDeplo
column.typeIdentifier should be(TI.Float)
column.isRequired should be(false)
}

"Encountering an unsupported type should not error and just ignore the column" in {
val postgres =
s"""
| CREATE TABLE blog (
| id SERIAL PRIMARY KEY, -- implicit primary key constraint
| test DATE
|);
""".stripMargin

val mysql =
s"""
| CREATE TABLE blog (
| id int NOT NULL,
| PRIMARY KEY(id),
| test DATE
| );
""".stripMargin

val initialResult = setup(SQLs(postgres = postgres, mysql = mysql, sqlite = ""))

val dataModel =
s"""
|type Blog @db(name: "blog"){
| id: Int! @id
|}
""".stripMargin

val result = deploy(dataModel, ConnectorCapabilities(IntIdCapability))

result should equal(initialResult)
}
}

0 comments on commit cdb8ca6

Please sign in to comment.