Code Monkey home page Code Monkey logo

Comments (10)

Maligosus avatar Maligosus commented on August 19, 2024 1

The files in prisma/migrations exist.

I decided to move the models to the prisma/schema folder, the problem disappeared.

Before this, the models were in the prisma root folder, and there was also a migrations folder.

At now i set current structure of prisma folder.

image

Thanks a lot.

from prisma.

janpio avatar janpio commented on August 19, 2024 1

No, there is definitely a problem when using --schema prisma that we need to reproduce and fix.

But thanks for the information, we will take it from here.

from prisma.

janpio avatar janpio commented on August 19, 2024

Hm, let's figure out what really is unexpected here.

You first show that you have no migrations in prisma/migrations, and then you run prisma migrate dev on a database that already has tables in there (which conflicts with the fact that there are not existing migrations) and also has recordings that there should be migrations that were applied to the database in the past (The following migration(s) are applied to the database but missing from the local migrations directory ...), so Prisma tells you that your database is in a drift state and suggests a reset to get your database into a clean state. That is normal, and could potentially be worked around with https://www.prisma.io/docs/orm/prisma-migrate/workflows/baselining if you really wanted.

All of this of course only makes sense if you indeed do not have local migrations in a migration directory. Is that really the case? You mentioned that you split your Prisma schema. Where did you put these files? The default folder to put them would be prisma/schema while the migrations stay in prisma/migrations.
Did you put the files directly in prisma instead, and that is the reason for --schema prisma in your commands?

from prisma.

janpio avatar janpio commented on August 19, 2024

So just to confirm, you tried to use ./prisma as the folder for prismaSchemaFolder and that led to problems?

from prisma.

Maligosus avatar Maligosus commented on August 19, 2024

So just to confirm, you tried to use ./prisma as the folder for prismaSchemaFolder and that led to problems?

Yes, there were *.prisma files and the folder with migrations in ./prisma folder.

from prisma.

janpio avatar janpio commented on August 19, 2024

Ok, I understand. Seems that using --schema prisma leads to the CLI not picking up the migrations folder any more, even though it tells you it is looking in the correct path. That is super unexpected.

from prisma.

Maligosus avatar Maligosus commented on August 19, 2024

Just in case
I ran command without --schema options after I moved *.prisma files to prisma/schema folder.
But yes it ignore prisma/migrations folder if i will set --schema=prisma

from prisma.

janpio avatar janpio commented on August 19, 2024

I ran command without --schema options after I moved *.prisma files to prisma/schema folder.

Interesting, to me it is unclear how that should treat multiple .prisma files in that folder and what should happen.
How did that work when you used the commands without --schema completely?

from prisma.

Maligosus avatar Maligosus commented on August 19, 2024

I found out.

The migrations folder should not be in the same folder as *.prisma files.

Then everything will work.

I think there is nothing to worry about anymore.

from prisma.

Maligosus avatar Maligosus commented on August 19, 2024

I confirm,

When use
npx prisma migrate dev --create-only --skip-generate --schema prisma

Prisma prefer to reset database.
It doesn't matter how the files are located, the problem still occurs.

My project structure ![image](https://github.com/prisma/prisma/assets/37801096/5a08ecc4-7a95-4956-a4a3-5f861b0f0246)
My main.prisma file
// 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"
  previewFeatures = ["prismaSchemaFolder"]
}

datasource db {
  provider = "postgresql"
  url      = env("DB_URL")
}
geo.prisma as example
model Country {
  id      Int      @id @default(autoincrement()) @db.Integer
  name    String   @unique @db.VarChar(255)
  color   String   @db.Char(7)
  code    String?  @db.VarChar(255)
  regions Region[]

  @@map("countries")
}

enum GeoObjectTypeEnum {
  COUNTRY  @map("country")
  REGION   @map("region")
  CITY     @map("city")
  DISTRICT @map("district")

  @@map("geo_object_type_enum")
}


model Region {
  id        Int     @id @default(autoincrement()) @db.Integer
  name      String  @db.VarChar(255)
  country   Country @relation(fields: [countryId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  countryId Int     @map("country_id") @db.Integer
  color     String  @db.Char(7)
  code      Int?    @db.Integer
  cities    City[]

  @@unique(fields: [countryId, name, code], map: "regions_country_id_name", name: "regionUniqueName")
  @@map("regions")
}

model City {
  id                 Int                  @id @default(autoincrement()) @db.Integer
  name               String               @db.VarChar(255)
  region             Region               @relation(fields: [regionId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  regionId           Int                  @map("region_id") @db.Integer
  color              String               @db.Char(7)
  code               Int?                 @unique @db.Integer
  districts          District[]
  levelGeography     LevelGeography[]
  cityCoordinates    CityCoordinates?
  cityCounting1Day   CityCounting1Day[]
  cityCounting1Week  CityCounting1Week[]
  cityCounting1Month CityCounting1Month[]
  cityCounting1Year  CityCounting1Year[]

  @@unique(fields: [regionId, name, code], map: "cities_unique_fields", name: "cityUniqueFields")
  @@map("cities")
}

model District {
  id                     Int                      @id @default(autoincrement()) @db.Integer
  name                   String                   @db.VarChar(255)
  city                   City                     @relation(fields: [cityId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  cityId                 Int                      @map("city_id") @db.Integer
  color                  String                   @db.Char(7)
  levelGeography         LevelGeography[]
  districtCoordinates    DistrictCoordinates?
  districtCounting1Day   DistrictCounting1Day[]
  districtCounting1Week  DistrictCounting1Week[]
  districtCounting1Month DistrictCounting1Month[]
  districtCounting1Year  DistrictCounting1Year[]

  @@unique(fields: [name, cityId], name: "districtUniqueFields", map: "districts_unique")
  @@map("districts")
}

model CityCoordinates {
  id      Int                             @id @default(autoincrement()) @db.Integer
  lat     Float                           @db.DoublePrecision
  lon     Float                           @db.DoublePrecision
  city    City                            @relation(fields: [cityId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  cityId  Int                             @unique @map("city_id") @db.Integer
  weather CityCoordinateWeatherForecast[]

  @@map("cities_coordinates")
}

model DistrictCoordinates {
  id         Int                                 @id @default(autoincrement()) @db.Integer
  lat        Float                               @db.DoublePrecision
  lon        Float                               @db.DoublePrecision
  district   District                            @relation(fields: [districtId], references: [id], onDelete: Cascade, onUpdate: Cascade)
  districtId Int                                 @unique @map("district_id") @db.Integer
  weather    DistrictCoordinateWeatherForecast[]

  @@map("districts_coordinates")
}

from prisma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.