Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV var is required to execute generate/validate #2686

Closed
janpio opened this issue Jun 8, 2020 · 4 comments
Closed

ENV var is required to execute generate/validate #2686

janpio opened this issue Jun 8, 2020 · 4 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/engines Issue for tech Engines.
Milestone

Comments

@janpio
Copy link
Member

janpio commented Jun 8, 2020

Bug description

image
image

How to reproduce

Run prisma generate on this schema:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

// ### Product ###
model Product {
  id              Int                @default(autoincrement()) @id
  name            String             @unique
  description     String?
  developerId     Int
  developer       ProductDeveloper   @relation(fields: [developerId], references: [id])
  forumId         Int?
  forum           Forum?             @relation(fields: [forumId], references: [id])
  type            ProductType
  tags            ProductTag[]
  salesPages      ProductSalesPage[]
  productVersions ProductVersions[]
  productPictures ProductPictures[]
  Customer        Customer?          @relation(fields: [customerId], references: [id])
  customerId      Int?
  Invoice         Invoice?           @relation(fields: [invoiceId], references: [id])
  invoiceId       Int?
  owner           Seller             @relation(fields: [ownerId], references: [id])
  ownerId         Int
}

enum ProductType {
  Plugins_WordPress
  Temas_WordPress
}

model ProductDeveloper {
  id       Int       @default(autoincrement()) @id
  name     String    @unique
  products Product[]
}

model ProductTag {
  id          Int       @default(autoincrement()) @id
  name        String    @unique
  translation String
  products    Product[] @relation(references: [id])
}

model ProductSalesPage {
  id        Int     @default(autoincrement()) @id
  url       String  @unique
  productId Int
  product   Product @relation(fields: [productId], references: [id])
}

model ProductVersions {
  id                  Int          @default(autoincrement()) @id
  provider            Provider
  isCompacted         Boolean      @default(false)
  version             String
  lastUpdated         String?
  isUnlocked          Boolean      @default(false)
  warning             String?
  createdAt           DateTime     @default(now())
  downloadHost        downloadHost
  downloadHostAccount Int
  downloadPath        String
  productId           Int
  product             Product      @relation(fields: [productId], references: [id])
}

model ProductPictures {
  id         Int     @default(autoincrement()) @id
  pictureUrl String  @unique
  productId  Int
  product    Product @relation(fields: [productId], references: [id])
}

// ### User ###
model User {
  id              Int                   @default(autoincrement()) @id
  name            String
  email           String                @unique
  login           String                @unique
  balance         Float                 @default(0.00)
  isSuspended     Boolean               @default(false)
  suspendedReason String?
  createdAt       DateTime              @default(now())
  tags            UserTag[]             @relation(references: [id])
  accounts        UserPlatformAccount[]
  customer        Customer?
  seller          Seller?
}

model UserPlatformAccount {
  id             Int                @default(autoincrement()) @id
  nickname       String?
  platformUserId String
  platform       SupportedPlatforms
  details        Json
  userId         Int
  user           User               @relation(fields: [id], references: [id])
}

model UserTag {
  id    Int    @default(autoincrement()) @id
  value String @unique
  users User[] @relation(references: [id])
}

// ### Customer ###
model Customer {
  id        Int       @default(autoincrement()) @id
  birthday  DateTime?
  cpf       String?   @unique
  gender    Gender?
  createdAt DateTime  @default(now())
  invoices  Invoice[]
  product   Product[]
  userId    Int
  user      User      @relation(fields: [userId], references: [id])
  // Criar um resolver na API GraphQL para pegar os produtos de acordo com as
  // invoices que estão pagas.
}

// ### Seller ###
model Seller {
  id        Int        @default(autoincrement()) @id
  role      SellerRole
  cpf       String     @unique
  createdAt DateTime   @default(now())
  invoices  Invoice[]
  product   Product[]
  userId    Int
  user      User       @relation(fields: [userId], references: [id])
}

enum SellerRole {
  ADMIN
  RESELLER
}

// Global model and enums
model Forum {
  id        Int      @default(autoincrement()) @id
  name      String
  permalink String   @unique
  parentId  Int?
  parent    Forum?   @relation(fields: [parentId], references: [id])
  Forum     Forum[]  @relation("ForumToForum")
  product   Product?
}

model Host {
  id        Int          @default(autoincrement()) @id
  host      downloadHost
  accountId String
}

model Invoice {
  id                Int                  @default(autoincrement()) @id
  status            InvoiceStatus
  transactions      PaymentTransaction[]
  purchaseDate      DateTime
  products          Product[]
  supportExpiration DateTime
  customerId        Int
  customer          Customer             @relation(fields: [customerId], references: [id])
  sellerId          Int
  seller            Seller               @relation(fields: [sellerId], references: [id])
}

enum InvoiceStatus {
  PAID
  OVERDUE
  REFUNDED
  CANCELLED
}

model PaymentTransaction {
  id            Int                        @default(autoincrement()) @id
  transactionID Int                        @unique
  platform      PaymentTransactionPlatform
  date          DateTime
  details       Json
  value         Float
  invoiceId     Int
  invoice       Invoice                    @relation(fields: [invoiceId], references: [id])
}

enum PaymentTransactionPlatform {
  MERCADOPAGO
}

enum Gender {
  M
  F
}

enum Provider {
  GPLZONE
  ULTRAPACKV2
}

enum downloadHost {
  DROPBOX
}

enum SupportedPlatforms {
  FORUM
  MERCADOLIBRE
}

Expected behavior

I can generate a Prisma Client.

Environment & setup

  • OS: Windows
  • Database: -
  • Prisma version:
λ prisma -v
Environment variables loaded from ./prisma/.env
@prisma/cli          : 2.0.0-beta.8
Current platform     : windows
Query Engine         : query-engine 12105ee25e61860c17a381ffdfcf2b2513b0ba92 (at C:\ProgramData\nvm\v12.6.0\node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 12105ee25e61860c17a381ffdfcf2b2513b0ba92 (at C:\ProgramData\nvm\v12.6.0\node_modules\@prisma\cli\migration-engine-windows.exe)
Introspection Engine : introspection-core 12105ee25e61860c17a381ffdfcf2b2513b0ba92 (at C:\ProgramData\nvm\v12.6.0\node_modules\@prisma\cli\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 12105ee25e61860c17a381ffdfcf2b2513b0ba92 (at C:\ProgramData\nvm\v12.6.0\node_modules\@prisma\cli\prisma-fmt-windows.exe)
  • Node.js version: v12.6.0
@janpio janpio changed the title ENV var is required to execute generate ENV var is required to execute generate/validate Jun 8, 2020
@Jolg42
Copy link
Member

Jolg42 commented Jun 8, 2020

I could also reproduce with a minimal schema with 2.0.0-alpha.1307:

generator client {
  provider = "prisma-client-js"
}

// Works
datasource postgresdb {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id Int @default(autoincrement()) @id
}

It looks like it happens only for mysql (and sqlite, see next comment)

generator client {
  provider = "prisma-client-js"
}

// Errors error: Error validating datasource `db`: The URL for datasource `db` must start with the protocol `mysql://`.
datasource mysqldb {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model User {
  id Int @default(autoincrement()) @id
}

@Jolg42 Jolg42 added the bug/2-confirmed Bug has been reproduced and confirmed. label Jun 8, 2020
@Jolg42 Jolg42 added this to the Beta 9 milestone Jun 8, 2020
@Jolg42 Jolg42 added the kind/bug A reported bug. label Jun 8, 2020
@Jolg42
Copy link
Member

Jolg42 commented Jun 8, 2020

Also happens with SQLite
Screen Shot 2020-06-08 at 12 46 38

generator client {
  provider = "prisma-client-js"
}

datasource sqlitedb {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model User {
  id Int @default(autoincrement()) @id
}

@Jolg42 Jolg42 added the tech/engines Issue for tech Engines. label Jun 8, 2020
@Ly0ko
Copy link

Ly0ko commented Jun 10, 2020

Also happens with postgresql

image
image

@Jolg42
Copy link
Member

Jolg42 commented Jun 10, 2020

@tylerdotdev check your .env file next to the schema.prisma file and fix the DATABASE_URL and it should work after 😃

This thread is focusing on the fact that validation should ignore the .env file in this case. And only check it later when actually querying.
In other terms only validating the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. tech/engines Issue for tech Engines.
Projects
None yet
Development

No branches or pull requests

4 participants