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

db pull can't parse script setting default value #23453

Closed
Alicia-bites opened this issue Mar 12, 2024 · 6 comments · Fixed by prisma/prisma-engines#4884
Closed

db pull can't parse script setting default value #23453

Alicia-bites opened this issue Mar 12, 2024 · 6 comments · Fixed by prisma/prisma-engines#4884
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/bug A reported bug. topic: CREATE DEFAULT ... AS ... topic: default topic: prisma db pull CLI: prisma db pull topic: sql server Microsoft SQL Server topic: unwrap error
Milestone

Comments

@Alicia-bites
Copy link

Alicia-bites commented Mar 12, 2024

Bug description

When I try to introspect the database, I get an error about a script that sets a default value for a column as 'Non'.

Here is the script :

/****** Object:  Default dbo.Non    Script Date: 21/12/98 09:42:22 ******/
/****** Object:  Default dbo.Non    Script Date: 03/12/98 14:41:54 ******/
/****** Object:  Default dbo.Non    Script Date: 20/10/98 14:23:35 ******/
/****** Object:  Default dbo.Non    Script Date: 19/10/98 09:48:52 ******/
/****** Objet:  valeur par défaut: dbo.Non    Date de script: 16/10/98 18:26:53 ******/
create default Non as 'Non'

How to reproduce

npx prisma db pull

Expected behavior

The introspection get all the tables from the database and translate them into models in schema.prisma

Prisma information

npx prisma db pull

schema :

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["views"]
}

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

Environment & setup

  • OS: Ubuntu
  • Database: SQL Server
  • Node.js version: v20.11.1

Prisma Version

Environment variables loaded from .env
prisma                  : 5.10.2
@prisma/client          : 5.10.2
Computed binaryTarget   : debian-openssl-3.0.x
Operating System        : linux

@Alicia-bites Alicia-bites added the kind/bug A reported bug. label Mar 12, 2024
@janpio
Copy link
Contributor

janpio commented Mar 12, 2024

What error are you getting?
How can we reproduce this?

@Alicia-bites
Copy link
Author

Alicia-bites commented Mar 12, 2024

Hello! Thank you for the answer :)

Here is the error:

➜  backend git:(talking_to_neoler) ✗ npx prisma db pull              talking_to_neoler ✱ ◼
Prisma schema loaded from prisma/schema.prisma
Environment variables loaded from .env
Datasource "db": SQL Server database

✖ Introspecting based on datasource defined in prisma/schema.prisma

Oops, an unexpected error occurred!
Error in Schema engine.
Reason: [schema-engine/sql-schema-describer/src/mssql.rs:348:30] called `Result::unwrap()` on an `Err` value: "Couldn't parse default value: `/****** Object:  Default dbo.Non    Script Date: 21/12/98 09:42:22 ******/\r\n/****** Object:  Default dbo.Non    Script Date: 03/12/98 14:41:54 ******/\r\n/****** Object:  Default dbo.Non    Script Date: 20/10/98 14:23:35 ******/\r\n/****** Object:  Default dbo.Non    Script Date: 19/10/98 09:48:52 ******/\r\n/****** Objet:  valeur par défaut: dbo.Non    Date de script: 16/10/98 18:26:53 ******/\r\ncreate default Non as 'Non'\r\n`"

To reproduce it you would need to connect to my database.

@janpio janpio added topic: sql server Microsoft SQL Server topic: default bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. labels Mar 12, 2024
@janpio janpio added the topic: prisma db pull CLI: prisma db pull label May 23, 2024
@janpio janpio changed the title db pull can't parse script setting default value db pull can't parse script setting default value May 23, 2024
@janpio janpio added domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. and removed domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. labels May 23, 2024
@Weakky
Copy link
Member

Weakky commented May 23, 2024

Hey @Alicia-bites, is there any chance you could share with us your sql database schema? Even privately if needed. That would help us a lot to reproduce your issue. Thank you 🙏

@janpio
Copy link
Contributor

janpio commented May 23, 2024

(For us the default is just ignored and not represented in the Prisma schema: #12150)

@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels May 23, 2024
@janpio
Copy link
Contributor

janpio commented May 23, 2024

@Alicia-bites I investigated this problem a bit further, and it seem that the error message is slightly misleading. The CREATE DEFAULT ... AS ... itself is not the problem, it is how that default is used in some tables. We can not figure out how to create a database that triggers this error, so it would be really helpful if you could help us out here. Can you please also shared which SQL Server version you were using here?

@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels May 23, 2024
@janpio janpio self-assigned this May 23, 2024
@janpio
Copy link
Contributor

janpio commented May 23, 2024

I actually figured it out: #24275 The comment before the actual SQL is the problem.

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. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. kind/bug A reported bug. topic: CREATE DEFAULT ... AS ... topic: default topic: prisma db pull CLI: prisma db pull topic: sql server Microsoft SQL Server topic: unwrap error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants