#[help wanted] setting up migrations on existing database

16 messages · Page 1 of 1 (latest)

crude valley
#

I have setup prima, and its been great from using the generate and being able to use my database effectively in JS. My issue has come from trying to add a couple of columns to a table.

npx prisma db pull 
npx prisma generate
mkdir -p prisma/migrations/0_init
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql
npx prisma migrate dev --name some name

This results in the following

The migration `0_init` was modified after it was applied.
? We need to reset the "public" schema at "lallah.db.elephantsql.com"

Yet nothing was updated or changed, I ran all the commands one after another

rich ibex
#

👋 Hi @crude valley

#

After the npx prisma migrate diff command, the next command should be npx prisma migrate resolve --applied 0_init. To mark the initial migration as already applied. Does that work?

crude valley
#

I will try in a bit, just away from the computer at the moment

rich ibex
#

no problem at all

crude valley
#
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "wbvuoaux", schema "public" at "lallah.db.elephantsql.com"
Error: P3008

The migration `0_init` is already recorded as applied in the database.

I can't be sure if I done this since I reset and started again. where is this record of the applied migrations held?

rich ibex
#

I believe it's _PrismaMigrations ?

crude valley
#

where is that located?

#

ah its a table

#

Does't seem to exist

#
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "wbvuoaux", schema "public" at "lallah.db.elephantsql.com"

1 migration found in prisma/migrations


Database schema is up to date!```
#

but when I run the migrate dev command it gives the same error

#

I created a new migration and the script matches the 0_init

#

I applied that one and I seem to have got further. Not sure how to locate the _prisma_migrations table

#

I have found the table

#

I am getting new error now thought

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "wbvuoaux", schema "public" at "lallah.db.elephantsql.com"

Error: P3006

Migration `1_update` failed to apply cleanly to the shadow database. 
Error:
db error: ERROR: relation "donations" already exists
   0: schema_core::state::DevDiagnostic
             at schema-engine/core/src/state.rs:270

even though I marked as applied it seems it wasnt to try to apply it again? I was expecting it to work out there no changes.