prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.8k stars 1.56k forks source link

`prisma migrate reset` error, cockroachdb, if the schema has relation and data that depends on #18222

Open meepeek opened 1 year ago

meepeek commented 1 year ago

Bug description

@janpio from #4602 I have got the similar error, using the setup in reproduce section. This is my environment

How to reproduce

cockrochdb setup docker-compose.yml

version: '3.5'

services:
 crdb:
   image: cockroachdb/cockroach
   ports:
     - "26257:26257"
     - "8080:8080"
   command: start-single-node --insecure

connection string

DATABASE_URL="postgres://root@localhost:26257/mydb?sslmode=disable"

generate schema, push to db and put some data into both models by studio and then

prisma migrate reset
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": CockroachDB database "mydb", schema "public" at "localhost:26257"

✔ Are you sure you want to reset your database? All data will be lost. … yes

Error: P3016

The fallback method for database resets failed, meaning Migrate could not clean up the database entirely. Original error: 
db error: ERROR: "Quote" is referenced by foreign key from table "SymbolInfo"
   0: sql_migration_connector::best_effort_reset
           with namespaces=None
             at migration-engine/connectors/sql-migration-connector/src/lib.rs:333
   1: migration_core::state::Reset
             at migration-engine/core/src/state.rs:425

Expected behavior

It should reset the database

Prisma information

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

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "darwin-arm64"]
  output   = "./client"
}

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

model Quote {
  id           BigInt                @id @default(autoincrement())
  symbol       String
  market       String
  source       String
  type         String?
  sub_type     String?
  symbol_info  SymbolInfo?
  settrade_eod SettradeStockEod[]

  @@unique([symbol, market])
}

model SymbolInfo {
  id             BigInt     @id @default(autoincrement())
  name_en        String?
  name_th        String?
  timezone       String?
  finnomena_id   String?
  pair_id        BigInt?
  jitta_currency String?
  jitta_unit     String?
  quote          Quote   @relation(fields: [quote_id], references: [id])
  quote_id       BigInt     @unique
}

Environment & setup

Prisma Version

prisma                  : 4.10.1
@prisma/client          : 4.11.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine aead147aa326ccb985dcfed5b065b4fdabd44b19 (at ../../../../Library/pnpm/global/5/.pnpm/@prisma+engines@4.10.1/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli aead147aa326ccb985dcfed5b065b4fdabd44b19 (at ../../../../Library/pnpm/global/5/.pnpm/@prisma+engines@4.10.1/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.10.1-1.80b351cc7c06d352abe81be19b8a89e9c6b7c110
Default Engines Hash    : aead147aa326ccb985dcfed5b065b4fdabd44b19
Studio                  : 0.481.0
tgrant59 commented 1 year ago

I'm also seeing this same issue FYI. DB resets are failing

GV14982 commented 1 year ago

+1 on this, seeing the same issue on version 5.2.0

jleni commented 11 months ago

same here