I am having some problems with a production databa...
# orm-help
n
I am having some problems with a production database, all the migrations have been applied but suddenly its giving an error about a failed migration, but it shows no logs. How do I debug this ?
Copy code
/app # npx prisma migrate deploy
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "rss_bot_database.db" at "file:./../config/rss_bot_database.db"

3 migrations found in prisma/migrations

Error: P3009

migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>
The `init` migration started at 2022-06-09 13:06:17.104 UTC failed with the following logs:


/app #
When I try to use
npx prisma migrate apply --applied "migration_name"
it says all the migrations are applied
👀 1
a
Hey Norbert! Have you tried running
npx prisma migrate resolve --applied "migration_name"
? docs
n
Hey, yes. You can see it in the end of my message
a
Your command shows
prisma migrate apply
, I’m asking about
prisma migrate resolve
n
I think that was a typo on my side. Its giving the same result. I tried the command with all the migrations
The database works, but its not really promissing
a
Are you using multiple database by chance? Prisma uses the
_prisma_migrations
table to do some internal bookkeeping on the state of your database migrations. Could you query everything from that table and provide the output here?
Copy code
select * from _prisma_migrations
n
here is the output:
Copy code
sqlite> select * from _prisma_migrations;
c1da8a81-e83c-4431-a4be-2b053c978a74|f57024a9c774cb070f48a57b4d978b49ffd948e593e7432e0dc111746559b94b|1653196956992|2022052203000_init|||1653196956967|1
b6f2f099-2e86-4861-bf78-5fa328bdf91e|c02bd42bb515f8dc6322c33619007a7676ab25b4a4f4895a840e4edf71eee266|1653196957017|20220522034158_multichat|||1653196956993|1
728fdc88-2679-469a-8e1f-329963f8b5ac|7f7347ccf8e35f5e7586c9f51c9bbcfafc0bc310135be3b226d4f0e85052490f|1654452375079|20220605145537_disable_rss_feed|||1654452375044|1
af63229f-7d25-45d2-aeaf-e451cc0dde0e|f57024a9c774cb070f48a57b4d978b49ffd948e593e7432e0dc111746559b94b||init|A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: <https://pris.ly/d/migrate-resolve>

Migration name: init

Database error code: 1

Database error:
table "rss" already exists
   0: sql_migration_connector::apply_migration::apply_script
           with migration_name="init"
             at migration-engine/connectors/sql-migration-connector/src/apply_migration.rs:104
   1: migration_core::commands::apply_migrations::Applying migration
           with migration_name="init"
             at migration-engine/core/src/commands/apply_migrations.rs:49
   2: migration_core::state::ApplyMigrations
             at migration-engine/core/src/state.rs:183

   0: sql_migration_connector::apply_migration::apply_script
           with migration_name="init"
             at migration-engine/connectors/sql-migration-connector/src/apply_migration.rs:104
   1: migration_core::commands::apply_migrations::Applying migration
           with migration_name="init"
             at migration-engine/core/src/commands/apply_migrations.rs:49
   2: migration_core::state::ApplyMigrations
             at migration-engine/core/src/state.rs:183||1654779977104|0
sqlite>
The innit migration has been manually made. Its supposed to be applied only once. Here is the content of the migration
This migration was used to migrate an old database structure
Copy code
-- CreateTable
CREATE TABLE "rss" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "link" TEXT NOT NULL,
    "last" TEXT NOT NULL,
    "name" TEXT NOT NULL
);

-- CreateIndex
Pragma writable_schema=1;
CREATE UNIQUE INDEX "sqlite_autoindex_rss_1" ON "rss"("id");
Pragma writable_schema=0;

-- CreateIndex
Pragma writable_schema=1;
CREATE UNIQUE INDEX "sqlite_autoindex_rss_2" ON "rss"("link");
Pragma writable_schema=0;

-- CreateIndex
Pragma writable_schema=1;
CREATE UNIQUE INDEX "sqlite_autoindex_rss_3" ON "rss"("name");
Pragma writable_schema=0;
a
Sorry for the delay on this one. The
_prisma_migrations
table shows 4 migrations, but the
migrations
folder only has 3 migrations in it, so something got out of sync at some point. Have you tried
npx prisma migrate resolve --applied 'init'
?
n
Yes as you can see on the screenshot I did