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

[bug]: prisma throw's error while testing #23923

Open
Sonichigo opened this issue Apr 23, 2024 · 2 comments
Open

[bug]: prisma throw's error while testing #23923

Sonichigo opened this issue Apr 23, 2024 · 2 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: bun Bun is a fast all-in-one JavaScript runtime topic: migrate

Comments

@Sonichigo
Copy link

Bug description

Error: Schema engine error:
Incorrect number of parameters given to a statement. Expected 1: got: 0.

error: script "start:migrate:prod" exited with code 1

How to reproduce

Below is my test file code test.test.js

const {expect} = require("@jest/globals");
const keploy = require("@keploy/sdk");
const timeOut = 300000;
import { test } from "bun:test";

test(
      "TestKeploy",
      (done) => {
        const cmd = "bun start:migrate:prod";
        const options = {};
        keploy.Test(cmd, options, (err, res) => {
          if (err) {
            done(err);
          } else {
            expect(res).toBeTruthy(); // Assert the test result
            done();
          }
        });
      },
      timeOut
);

There are a bit config need to be done before hand such as:-

...
# other scripts
    "test": "jest --coverage --collectCoverageFrom='src/**/*.{js,jsx}'",
    "coverage": "nyc npm test && npm run coverage:merge && npm run coverage:report",
    "coverage:merge": "mkdir -p ./coverage && nyc merge ./coverage .nyc_output/out.json",
    "coverage:report": "nyc report --reporter=lcov --reporter=text"
...

and installing jest and nyc with bun

bun i nyc @keploy/sdk jest

This issue is replicable incase of both node and bun with js and ts.

Expected behavior

No response

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
  provider = "prisma-client-js"
  binaryTargets   = ["native", "darwin-arm64", "linux-musl", "linux-arm64-openssl-1.1.x"]
}

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

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String?
  password  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
 
  posts  Post[]
  
  comments  Comment[]
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  body      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  user      User     @relation(fields: [userId], references: [id])
  userId    Int

  comments  Comment[]
}

model Comment {
  id        Int      @id @default(autoincrement())
  body      String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  
  user      User     @relation(fields: [userId], references: [id])
  userId    Int
  
  post   Post  @relation(fields: [postId], references: [id])
  postId Int
}

Environment & setup

  • OS: Lima-Debian-12
  • Database: PostgreSQL
  • Node.js version: v18.19.0, Npm version: 9.2.0, Bun --version 1.1.4

Prisma Version

prisma                  : 5.12.1
@prisma/client          : 5.12.1
Computed binaryTarget   : linux-arm64-openssl-3.0.x
Operating System        : linux
Architecture            : arm64
Node.js                 : v18.19.0
Query Engine (Node-API) : libquery-engine 473ed3124229e22d881cb7addf559799debae1ab (at node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 473ed3124229e22d881cb7addf559799debae1ab (at node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.12.0-21.473ed3124229e22d881cb7addf559799debae1ab
Default Engines Hash    : 473ed3124229e22d881cb7addf559799debae1ab
Studio                  : 0.499.0
@Sonichigo Sonichigo added the kind/bug A reported bug. label Apr 23, 2024
@Weakky Weakky added team/schema Issue for team Schema. bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. topic: migrate labels Apr 24, 2024
@Weakky
Copy link
Member

Weakky commented Apr 24, 2024

Hey @Sonichigo,

The error you posted references a custom script of yours start:migrate:prod. Could you share with us:

  • The underlying prisma command that is run by start:migrate:prod
  • Any migration script that you think is triggering this error

Thank you 🙏

@Sonichigo
Copy link
Author

Hey @Weakky ,
This is my script

"start:migrate:prod": "prisma migrate dev && bun --watch index.ts",

I'm not sure why this is happening, same happen in case when i'm running my application with docker. The migration folder has this sql:-

-- CreateTable
CREATE TABLE "User" (
    "id" SERIAL NOT NULL,
    "email" TEXT NOT NULL,
    "name" TEXT,
    "password" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Post" (
    "id" SERIAL NOT NULL,
    "title" TEXT NOT NULL,
    "body" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" INTEGER NOT NULL,

    CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Comment" (
    "id" SERIAL NOT NULL,
    "body" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "userId" INTEGER NOT NULL,
    "postId" INTEGER NOT NULL,

    CONSTRAINT "Comment_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- AddForeignKey
ALTER TABLE "Post" ADD CONSTRAINT "Post_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

the migration-lock.toml

# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"

here's my dockerfile

FROM oven/bun:latest

RUN apt-get update && \
    apt-get install -y --no-install-recommends ca-certificates && \
    rm -rf /var/lib/apt/lists/* 

# Install nodejs using n
ARG NODE_VERSION=20
RUN apt update \
    && apt install -y curl
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
    && bash n $NODE_VERSION \
    && rm n \
    && npm install -g n
    
COPY . .

RUN bun install

RUN npx prisma migrate dev --name init
RUN bunx prisma generate

EXPOSE 4040

CMD ["bun", "--watch","start:migrate:prod"]

@janpio janpio added the topic: bun Bun is a fast all-in-one JavaScript runtime label Apr 24, 2024
@SevInf SevInf added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: bun Bun is a fast all-in-one JavaScript runtime topic: migrate
Projects
None yet
Development

No branches or pull requests

4 participants