prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Deployment fails for Chinook db

Open timsuchanek opened this issue 6 years ago • 1 comments

For this datamodel:

type Album {
  id: Int! @id @db(name:"AlbumId")
  Title: String!
  Artist: Artist! @db(name:"ArtistId")
  Tracks: [Track]
}

type Track {
  id: Int! @id @db(name:"TrackId")
  Name: String!
  Album: Album @db(name: "AlbumId")
  AlbumId: Int
  MediaType: MediaType! @db(name: "MediaTypeId")
  Genre: Genre @db(name: "GenreId")
  Composer: String
  Milliseconds: Int!
  UnitPrice: Float!
  Playlists: [Playlist] @relation(name:"PlaylistTrack")
}

type MediaType {
  id: Int! @id @db(name:"MediaTypeId")
  Name: String
}

type Genre {
  id: Int! @id @db(name:"GenreId")
  Name: String
  Tracks: [Track]
}

type Artist {
  id: Int! @id @db(name:"ArtistId")
  Name: String
  Albums: [Album]
}

type Customer {
  id: Int! @id @db(name:"CustomerId")
  FirstName: String!
  LastName: String!
  Company: String
  Address: String
  City: String
  State: String
  Country: String
  PostalCode: String
  Phone: String
  Fax: String
  Email: String!
  SupportRep: Employee @db(name: "SupportRepId")
}

type Employee {
  id: Int! @id @db(name:"EmployeeId")
  FirstName: String!
  LastName: String!
  Title: String
  ReportsTo: Employee
  BirthDate: DateTime
  HireDate: DateTime
  Address: String
  City: String
  State: String
  Country: String
  PostalCode: String
  Phone: String
  Fax: String
  Email: String
}

type Invoice {
  id: Int! @id @db(name:"InvoiceId")
  Customer: Customer! @db(name: "CustomerId")
  InvoiceDate: DateTime!
  BillingAddress: String
  BillingCity: String
  BillingState: String
  BillingCountry: String
  BillingPostalCode: String
  Total: Float!
  Lines: [InvoiceLine]
}

type InvoiceLine {
  id: Int! @id @db(name:"InvoiceLineId")
  Invoice: Invoice! @db(name: "InvoiceId")
  Track: Track! @db(name: "TrackId")
  UnitPrice: Float!
  Quantity: Int!
}

type Playlist {
  id: Int! @id @db(name:"PlaylistId")
  Name: String
  Tracks: [Track] @relation(name:"PlaylistTrack")
}

type PlaylistTrack @relationTable {
  PlaylistId: Playlist
  TrackId: Track
}

Deploying to a Postgres 11 with Prisma 1.33 I get the following error:

 â–¸    The Migration failed and has not been performed. This is very likely not a transient issue.
 â–¸    org.postgresql.util.PSQLException: ERROR: column "AlbumId" of relation "Track" already exists
 â–¸    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2433)
 â–¸    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2178)
 â–¸    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
 â–¸    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
 â–¸    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
 â–¸    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
 â–¸    at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:144)
 â–¸    at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:38)
 â–¸    at slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:21)
 â–¸    at slick.jdbc.Invoker.first(Invoker.scala:30)
 â–¸    at slick.jdbc.Invoker.first$(Invoker.scala:29)
 â–¸    at slick.jdbc.StatementInvoker.first(StatementInvoker.scala:15)
 â–¸    at slick.jdbc.StreamingInvokerAction$HeadAction.run(StreamingInvokerAction.scala:52)
 â–¸    at slick.jdbc.StreamingInvokerAction$HeadAction.run(StreamingInvokerAction.scala:51)
 â–¸    at slick.basic.BasicBackend$DatabaseDef$$anon$2.liftedTree1$1(BasicBackend.scala:275)
 â–¸    at slick.basic.BasicBackend$DatabaseDef$$anon$2.run(BasicBackend.scala:275)
 â–¸    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 â–¸    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 â–¸    at java.lang.Thread.run(Thread.java:748)
 â–¸

timsuchanek avatar May 15 '19 10:05 timsuchanek

This seems to be a missing validation on our side. Track has a field called AlbumID and you are telling Prisma to store the inlineRelation to Album on the field AlbumID. This leads to us trying to create two columns named AlbumID.

One solution is to give the inlineRelation field a different name @db(name: "InlineAlbumId") for example. We should add a validation during deploy for that though.

The field AlbumId is only on the type since we at the moment haven't implemented the query optimisation to shortcut queries like track(where:{album:{id: "sampleId"}}) to look directly into the inline relation column. Once this is implemented there should be no more need for this duplicated field.

type Track {
  id: Int! @id @db(name:"TrackId")
  Name: String!
  Album: Album @db(name: "AlbumId")  <- db column will be called AlbumID
  AlbumId: Int                                               <- db column will be called AlbumID
  MediaType: MediaType! @db(name: "MediaTypeId")
  Genre: Genre @db(name: "GenreId")
  Composer: String
  Milliseconds: Int!
  UnitPrice: Float!
  Playlists: [Playlist] @relation(name:"PlaylistTrack")
}

do4gr avatar May 17 '19 08:05 do4gr