Skip to content

Introspect default value with backslashes causes problem when generating client #1888

@kldzj

Description

@kldzj

Bug description

Backslashes in SQL default values are not escaped properly and consequently return an invalid schema when introspecting.

How to reproduce

  1. Create table with one or more columns containing backslashes in the default value
CREATE TABLE test (
    `model_name_space` VARCHAR(255) NOT NULL DEFAULT 'xyz\\Datasource\\Model'
)
  1. Introspect the database schema (prisma2 introspect)
  2. Generate client (prisma2 generate fails)

The generated schema will look like this:

model test {
    model_name_space    String    @default("xyz\Datasource\Model")
}

The following error is thrown when generating the client:

➜  prisma npx prisma2 generate  
Error: Schema parsing
error: Unexpected token. Expected one of: string interpolation start
  -->  schema.prisma:1552
     | 
1552 |   model_name_space                 String                          @default("xyz\Datasource\Model")
     |                                                                                 ^ Unexpected token.
     |

Expected behavior

Backslashes in the default value should be escaped.

model test {
    model_name_space    String    @default("xyz\\Datasource\\Model")
}

Prisma information

Environment & setup

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions