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.23k stars 1.53k forks source link

consequent run `prisma migrate reset --force` does not run migrates #18528

Open Kukunin opened 1 year ago

Kukunin commented 1 year ago

Bug description

I'm trying to setup integration testing using Prisma and Jest. I do run prisma migrate reset --force command for a testing database before running the test suite. The command runs great, but there are no tables that defined in my migrations. I believe it's not an expected behavior.

I could fix by running TRUNCATE _prisma_migrations before running prisma migrate reset --force, so it applies migrations one more time

How to reproduce

  1. Run npx dotenv -e .env.test -- npx prisma migrate reset --force
  2. See that migrations were ran well and all tables were created
  3. Run npx dotenv -e .env.test -- npx prisma migrate reset --force one more time
  4. See that there are no tables (they were reset, but not re-created)

Expected behavior

prisma migrate reset --force should be idempotent and maintain the clean and latest state of the database

Prisma information

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

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  schemas  = ["sync", "paap"]
}

model SalesforceAccount {
  id                String              @id(map: "salesforce_accounts_pk")
  description       String?
  baseUrl           String              @map("base_url")
  clientId          String              @map("client_id")
  clientSecret      String              @map("client_secret")
  username          String
  password          String              
  discovery         Json?
  salesforceTables  SalesforceTable[]

  @@schema("sync")
  @@map("salesforce_accounts")
}

model SalesforceTable {
  accountId              String              @map("id_account")
  name                   String
  table                  String
  columns                String[]
  intervalMinutes        Int                 @map("interval_minutes")
  lastSynchronizedAt     DateTime?           @db.Timestamptz(6) @map("date_last_synchronized")
  account                SalesforceAccount   @relation(fields: [accountId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "salesforce_tables_fk")

  @@id([accountId, name], map: "salesforce_tables_pk")
  @@map("salesforce_tables")
  @@schema("sync")
}
// Add your code using Prisma Client

Environment & setup

Prisma Version

prisma                  : 4.11.0
@prisma/client          : 4.11.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash    : 8fde8fef4033376662cad983758335009d522acb
Studio                  : 0.483.0
Preview Features        : multiSchema
Kukunin commented 1 year ago

It's interesting, now I have multiple migrations in my project and it runs good. The bug occured when I had a single 0_init migration. I might need to create a github repo that reproduces the bug

akkonrad commented 4 weeks ago

just had this one too.