Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

migrate save and up always recreate the db #316

Closed
Weakky opened this issue Jan 22, 2020 · 9 comments
Closed

migrate save and up always recreate the db #316

Weakky opened this issue Jan 22, 2020 · 9 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.

Comments

@Weakky
Copy link
Member

Weakky commented Jan 22, 2020

Description

Given the following datamodel

datasource db {
  provider = "sqlite" // other options are: "mysql" and "sqlite"
  url      = "sqlite:./dev.db"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id String @id @default(cuid())
}

If you run prisma2 migrate save --experimental, you'll be prompted to create a new db if it doesn't exist.

Unfortunately, it'll always ask you to recreate it, even when using prisma2 migrate up --experimental

Here's the prompt:

You are trying to create a migration for Sqlite database /dev.db.
A database with that name doesn't exist at sqlite:./dev.db.
Do you want to create the database?

┌─ Database options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                                           │
│ ❯ Yes            Create new Sqlite database /dev.db                                                                                                       │
│   No             Don't create the database                                                                                                                │
│                                                                                                                                                           │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

It looks like /dev.db is used to check if the file already exists, instead of ./dev.db

@janpio janpio transferred this issue from prisma/prisma Jan 22, 2020
@pantharshit00
Copy link
Contributor

I am unable to reproduce this:
image

Can you please share your files in a Git reposiotory so that I can replicate the exact environment.

@pantharshit00 pantharshit00 added bug/0-needs-info More information is needed for reproduction. kind/bug A reported bug. labels Jan 22, 2020
@mikeslade
Copy link

mikeslade commented Jan 25, 2020

I am seeing the same issue.

prisma/schema.prisma

datasource db {
  provider = "sqlite"
  url      = "sqlite:./dev.db"
}

generator client {
  provider = "prisma-client-js"
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User?
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

Prisma2 version: 2.0.0-preview020.3

Windows 10

Start with prisma.schema file and package.json... nothing else.

run yarn or npm install

run npx prisma2 migrate save --experimental

select Yes at the create new database prompt

  • at this point the dev.db file is created in the appropriate location, but it is empty and the process hangs forever. No further errors or anything logged. I cannot seem to find a way around this. If I cancel the process and try again... it still thinks there is no database file and asks to create a new one. If you choose yes again, nothing happens...process just hangs.

@pantharshit00 pantharshit00 added bug/2-confirmed We have confirmed that this is a bug. and removed bug/0-needs-info More information is needed for reproduction. labels Jan 28, 2020
@pantharshit00
Copy link
Contributor

I can confirm this now. This doesn't happen when I use file protocol but it happens when I use the sqlite protocol.

@divyenduz

This comment has been minimized.

@janpio janpio removed the process/candidate Candidate for next Milestone. label Jan 31, 2020
@mikeslade
Copy link

Re-tested under 2.0.0-preview021 on Windows 10:
When using the file protocol and no initial db file, the initial run does create the file, but the process still never ends. If you then kill the terminal and run the migrate command again, it does work as expected.
sqlite protocol suffers as before

@pantharshit00
Copy link
Contributor

@mikeslade Refer to #342 for the windows issue.

@Jolg42 Jolg42 added the tech/typescript Issue for tech TypeScript. label May 26, 2020
@Jolg42 Jolg42 added the process/candidate Candidate for next Milestone. label Jul 8, 2020
@albertoperdomo albertoperdomo removed the process/candidate Candidate for next Milestone. label Jul 8, 2020
@Jolg42 Jolg42 added the process/candidate Candidate for next Milestone. label Aug 5, 2020
@albertoperdomo
Copy link
Contributor

@Jolg42 will repro

@albertoperdomo albertoperdomo removed the process/candidate Candidate for next Milestone. label Aug 5, 2020
@albertoperdomo albertoperdomo added this to the Backlog 2.5.0 milestone Aug 5, 2020
@Jolg42
Copy link
Member

Jolg42 commented Aug 12, 2020

I could reproduce with url = "sqlite:./dev.db and it works as expected with url = "file:./dev.db

It's also recommended that everybody switches to the file:.

@Jolg42
Copy link
Member

Jolg42 commented Aug 13, 2020

It is now fixed in the latest dev release and will be shipped in 2.5.0 🚢

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript.
Projects
None yet
Development

No branches or pull requests

7 participants