prisma / prisma/orm

Prisma should not use `SERIAL` when explicitly asked to use `@db.Integer` native type

Open
#5,705 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/feature topic: migrate topic: native database types topic: postgresql
Dominant language
TypeScript
Stars
47.6k
Forks
2.5k
Avg merge
21h 59m
Merged PRs (30d)
95

Description

Bug description

When I create a model with Int id field with mapping to db integer type (example from prisma native types docs):

id      Int      @id @default(autoincrement()) @postgres.Integer

It results in invalid prisma migrate statement "id" SERIAL NOT NULL,:

-- CreateTable
CREATE TABLE "NativeTypeModel" (
    "id" SERIAL NOT NULL,
    "bigInt" BIGINT,
    "byteA" BYTEA,
    "decimal" DECIMAL,

    PRIMARY KEY ("id")
);

How to reproduce

Use prisma schema provided below and run migrations

Expected behavior

It should generate sql with id column and autoincrement

Prisma information

datasource postgres {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  binaryTargets   = ["windows", "debian-openssl-1.1.x"]
  output          = "../prisma/generated/client"
  previewFeatures = ["groupBy", "createMany", "orderByRelation"]
}

model NativeTypeModel {
  id      Int      @id @default(autoincrement()) @postgres.Integer
  bigInt  BigInt?  @postgres.BigInt
  byteA   Bytes?   @postgres.ByteA
  decimal Decimal? @postgres.Decimal
}

Environment & setup

  • OS: WSL 2 (Ubuntu 20.04)
  • Database: Postgres
  • Node.js version: 15.8
  • Prisma version:
prisma               : 2.17.0
@prisma/client       : 2.17.0
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Studio               : 0.353.0
Preview Features     : groupBy, createMany, orderByRelation, nativeTypes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the migration using the Prisma schema in the issue and inspect the generated SQL, especially the id column. Compare the requested @postgres.Integer mapping with the SERIAL output; done when the migration preserves the explicit integer type while retaining autoincrement behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.