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

Error while using prisma migrate init: The above error occurred in the <TabIndexProvider> component: #521

Closed
joelewis opened this issue Jul 16, 2020 · 9 comments · Fixed by prisma/prisma#3284
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: tabindexprovider

Comments

@joelewis
Copy link

I'm starting to play around with prisma. And wanted to create my db tables using prisma migrate. Following the guide from https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch-prisma-migrate-typescript-postgres

After defining my prisma.schema file, I'm trying to generate the migrations using npx prisma migrate save --name init --experimental

But it's ending up with a blunt error in my terminal as below:

Environment variables loaded from prisma/.env
The above error occurred in the <TabIndexProvider> component:
    in TabIndexProvider
    in App

React will try to recreate this component tree from scratch using the error boundary you provided, App.
Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.

Machine/OS: Mac OS Mojave
Default Terminal Application

How to reproduce

Steps to reproduce the behavior:

  1. Follow instructions from https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch-prisma-migrate-typescript-postgres
  2. Execute npx prisma migrate save --name init --experimental
  3. See error

Expected behavior

Expected a successful command execution

Environment & setup

  • OS: Mac OS Mojave
  • Database: Mysql/SQLITE
  • Prisma version: 2.2.2
  • Node.js version: v12.3.1
@timleslie
Copy link

I am seeing the same error. I have followed the same instructions, the only difference that I am on postgres.

I used the example model definition in the startup guide.

I also see the same result with a stripped down schema.prisma file:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

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

model Post {
  id        Int      @default(autoincrement()) @id
  title     String
}

Interestingly, the _Migrations table is created in the database, so it appears it is getting at least as far as successfully connecting to, and performing operations on the database.

Generating the client before running migrations does not appear to make a difference.

I don't see the migrations directory being created that I would expect when the migrate command succeeded.

This issue is a blocker for some work I'm doing, so I will continue to dig down and try to find a root cause and try to provide any more observations which might be relevant.

@timleslie
Copy link

I have tried down-grading versions. I see the same error on 2.2.1. On 2.2.0 I get:

Environment variables loaded from prisma/.env
(node:19627) ExperimentalWarning: The fs.promises API is experimental
 ERROR  Oops, an unexpected error occured!
Error in migration engine.
Reason: [libs/sql-schema-describer/src/postgres.rs:484:20] querying for indices: Error { kind: QueryError(Error { kind: Closed, cause: None }), original_code: None, original_message: Some("connection closed") }

Please create an issue in the migrate repo with
your `schema.prisma` and the prisma command you tried to use 🙏:
https://github.com/prisma/migrate/issues/new

Please help us improve Prisma 2 by submitting an error report.
Error reports never contain personal or other sensitive information.
Learn more: https://pris.ly/d/telemetry

┌─ Submit error report ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                                                                                                                                                                                                                                                         │
│   Yes            Send error report once                                                                                                                                                                                                                                                 │
│ ❯ No             Don't send error report                                                                                                                                                                                                                                                │
│                                                                                                                                                                                                                                                                                         │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

@joelewis
Copy link
Author

Good find!

original_message: Some("connection closed")

This one sounds like a db specific error, I'm not sure. I'm guessing it should work fine for sqlite. Let me know if it works for a different DB. I should be able to proceed with sqlite then.

Thanks @timleslie

@timleslie
Copy link

@joelewis Haven't tried it with sqlite, I'm kind of tied to postgres for my current use case.

Running with DEBUG="*" gives a bit more info that might be useful.

(base) ➜  prisma-test DEBUG="*" npx prisma migrate save --name init --experimental
Environment variables loaded from prisma/.env
(node:20299) ExperimentalWarning: The fs.promises API is experimental
  MigrateEngine:rpc starting migration engine with binary: /Users/timleslie/src/prisma-test/node_modules/@prisma/cli/migration-engine-darwin +0ms
  MigrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"listMigrations","params":{"projectInfo":"","sourceConfig":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n"}} +5ms
  MigrateEngine:stderr Jul 17 14:05:21.331  INFO migration_engine: Starting migration engine RPC server git_hash="a9e8c3d97ef2a0cf59256e6b26097f2a80f0a6a4" +0ms
  MigrateEngine:stderr Jul 17 14:05:21.339  INFO quaint::single: Starting a postgresql pool with 1 connections. +7ms
  MigrateEngine:stderr Jul 17 14:05:21.350  INFO ListMigrations: migration_core::commands::list_migrations: Returning 0 migrations (0 pending). +11ms
  MigrateEngine:rpc SENDING RPC CALL {"id":2,"jsonrpc":"2.0","method":"inferMigrationSteps","params":{"projectInfo":"","sourceConfig":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n","datamodel":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n","migrationId":"DUMMY_NAME","assumeToBeApplied":[]}} +31ms
  MigrateEngine:stderr Jul 17 14:05:21.535 ERROR quaint::connector::postgres: Error in PostgreSQL connection: Error { kind: Closed, cause: None } +185ms
  MigrateEngine:stderr {"is_panic":true,"message":"[libs/sql-schema-describer/src/postgres.rs:484:20] querying for indices: Error { kind: QueryError(Error { kind: Closed, cause: None }), original_code: None, original_message: Some(\"connection closed\") }","backtrace":"   0: backtrace::backtrace::trace\n   1: backtrace::capture::Backtrace::new\n   2: user_facing_errors::Error::new_in_panic_hook\n   3: user_facing_errors::panic_hook::set_panic_hook::{{closure}}\n   4: std::panicking::rust_panic_with_hook\n   5: _rust_begin_unwind\n   6: core::panicking::panic_fmt\n   7: core::result::unwrap_failed\n   8: <sql_schema_describer::postgres::SqlSchemaDescriber as sql_schema_describer::SqlSchemaDescriberBackend>::describe::__describe::{{closure}}\n   9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  13: <migration_core::commands::infer_migration_steps::InferMigrationStepsCommand as migration_core::commands::command::MigrationCommand>::execute::__execute::{{closure}}\n  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  18: <futures_util::compat::compat03as01::Compat<Fut> as futures::future::Future>::poll\n  19: <futures::future::lazy::Lazy<F,R> as futures::future::Future>::poll\n  20: futures::future::chain::Chain<A,B,C>::poll\n  21: <futures::future::then::Then<A,B,F> as futures::future::Future>::poll\n  22: <futures::future::map::Map<A,F> as futures::future::Future>::poll\n  23: <futures::future::either::Either<A,B> as futures::future::Future>::poll\n  24: futures::task_impl::std::set\n  25: migration_engine::main::{{closure}}\n  26: tokio::runtime::enter::Enter::block_on\n  27: tokio::runtime::context::enter\n  28: tokio::runtime::handle::Handle::enter\n  29: migration_engine::main\n  30: std::rt::lang_start::{{closure}}\n  31: std::rt::lang_start_internal\n  32: _main\n"} +6ms
The above error occurred in the <TabIndexProvider> component:
    in TabIndexProvider
    in App

React will try to recreate this component tree from scratch using the error boundary you provided, App.
Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.
  prisma TypeError: Cannot read property 'Symbol(keypress-decoder)' of undefined
  prisma     at Object.emitKeypressEvents (readline.js:1043:13)
  prisma     at Object.useStdin (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2913327)
  prisma     at TabIndexProvider (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2313126)
  prisma     at renderWithHooks (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2706893)
  prisma     at mountIndeterminateComponent (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2736840)
  prisma     at beginWork$1 (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2752820)
  prisma     at Object._s (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2767616)
  prisma     at invokeGuardedCallback (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2770115)
  prisma     at Ou (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2812237)
  prisma     at performUnitOfWork (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2801113) +0ms

@timleslie
Copy link

Adding more debug env vars:

(base) ➜  prisma-test export RUST_LOG_FORMAT=devel
export RUST_BACKTRACE=1
export RUST_LOG=query_engine=debug,quaint=debug,query_core=trace,query_connector=debug,sql_query_connector=debug,prisma_models=debug,engineer=info,sql_introspection_connector=debug
export LOG_QUERIES=y

# Controls Scala test kit verbosity. Levels are trace, debug, info, error, warning
export LOG_LEVEL=debug

(base) ➜  prisma-test DEBUG="*" npx prisma migrate save --name init --experimental
Environment variables loaded from prisma/.env
(node:20613) ExperimentalWarning: The fs.promises API is experimental
  MigrateEngine:rpc starting migration engine with binary: /Users/timleslie/src/prisma-test/node_modules/@prisma/cli/migration-engine-darwin +0ms
  MigrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"listMigrations","params":{"projectInfo":"","sourceConfig":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n"}} +6ms
  MigrateEngine:stderr Jul 17 14:17:01.447  INFO migration_engine: Starting migration engine RPC server git_hash="a9e8c3d97ef2a0cf59256e6b26097f2a80f0a6a4" +0ms
  MigrateEngine:stderr Jul 17 14:17:01.469  INFO quaint::single: Starting a postgresql pool with 1 connections. +20ms
  MigrateEngine:stderr Jul 17 14:17:01.470  INFO quaint::connector::metrics: query="SELECT 1" item_type="query" params=[] duration_ms=0 +1ms
  MigrateEngine:stderr Jul 17 14:17:01.470  INFO quaint::connector::metrics: query="CREATE SCHEMA IF NOT EXISTS \"public\";" item_type="query" params=[] duration_ms=0 +0ms
  MigrateEngine:stderr Jul 17 14:17:01.472  INFO quaint::connector::metrics: query="CREATE TABLE \"public\".\"_Migration\" (\"revision\" SERIAL PRIMARY KEY NOT NULL, \"name\" TEXT NOT NULL, \"datamodel\" TEXT NOT NULL, \"status\" TEXT NOT NULL, \"applied\" INTEGER NOT NULL, \"rolled_back\" INTEGER NOT NULL, \"datamodel_steps\" TEXT NOT NULL, \"database_migration\" TEXT NOT NULL, \"errors\" TEXT NOT NULL, \"started_at\" timestamp(3) NOT NULL, \"finished_at\" timestamp(3));" item_type="query" params=[] duration_ms=2 +3ms
  MigrateEngine:stderr Jul 17 14:17:01.483  INFO ListMigrations: quaint::connector::metrics: query="SELECT \"public\".\"_Migration\".* FROM \"public\".\"_Migration\" ORDER BY \"revision\" ASC" item_type="query" params=[] duration_ms=10 +11ms
  MigrateEngine:stderr Jul 17 14:17:01.484  INFO ListMigrations: migration_core::commands::list_migrations: Returning 0 migrations (0 pending). +0ms
  MigrateEngine:rpc SENDING RPC CALL {"id":2,"jsonrpc":"2.0","method":"inferMigrationSteps","params":{"projectInfo":"","sourceConfig":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n","datamodel":"datasource db {\n  provider = \"postgresql\"\n  url      = env(\"DATABASE_URL\")\n}\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\nmodel Post {\n  id        Int      @default(autoincrement()) @id\n  title     String\n}\n","migrationId":"DUMMY_NAME","assumeToBeApplied":[]}} +48ms
  MigrateEngine:stderr Jul 17 14:17:01.488  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="SELECT \"public\".\"_Migration\".* FROM \"public\".\"_Migration\" WHERE \"status\" = $1 ORDER BY \"revision\" DESC LIMIT $2" item_type="query" params=["MigrationSuccess",2] duration_ms=2 +4ms
  MigrateEngine:stderr Jul 17 14:17:01.498  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="SELECT start_value, sequence_name\n                  FROM information_schema.sequences\n                  WHERE sequence_schema = $1" item_type="query" params=["public"] duration_ms=9 +11ms
  MigrateEngine:stderr Jul 17 14:17:01.504  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="SELECT t.typname as name, e.enumlabel as value\n            FROM pg_type t\n            JOIN pg_enum e ON t.oid = e.enumtypid\n            JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n            WHERE n.nspname = $1\n            ORDER BY name, value" item_type="query" params=["public"] duration_ms=5 +5ms
  MigrateEngine:stderr Jul 17 14:17:01.522  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="\n            SELECT\n                table_name,\n                column_name,\n                data_type,\n                udt_name as full_data_type,\n                character_maximum_length,\n                column_default,\n                is_nullable,\n                is_identity,\n                data_type\n            FROM information_schema.columns\n            WHERE table_schema = $1\n            ORDER BY column_name\n            COLLATE \"default\"\n        " item_type="query" params=["public"] duration_ms=18 +19ms
  MigrateEngine:stderr Jul 17 14:17:01.529  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="\n            SELECT\n                con.oid as \"con_id\",\n                att2.attname as \"child_column\",\n                cl.relname as \"parent_table\",\n                att.attname as \"parent_column\",\n                con.confdeltype,\n                conname as constraint_name,\n                child,\n                parent,\n                table_name\n            FROM\n            (SELECT\n                    unnest(con1.conkey) as \"parent\",\n                    unnest(con1.confkey) as \"child\",\n                    cl.relname AS table_name,\n                    generate_subscripts(con1.conkey, 1) AS colidx,\n                    con1.oid,\n                    con1.confrelid,\n                    con1.conrelid,\n                    con1.conname,\n                    con1.confdeltype\n                FROM\n                    pg_class cl\n                    join pg_namespace ns on cl.relnamespace = ns.oid\n                    join pg_constraint con1 on con1.conrelid = cl.oid\n                WHERE\n                    ns.nspname = $1\n                    and con1.contype = \'f\'\n                    ORDER BY colidx\n            ) con\n            JOIN pg_attribute att on\n                att.attrelid = con.confrelid and att.attnum = con.child\n            JOIN pg_class cl on\n                cl.oid = con.confrelid\n            JOIN pg_attribute att2 on\n                att2.attrelid = con.conrelid and att2.attnum = con.parent\n            ORDER BY con_id, con.colidx" item_type="query" params=["public"] duration_ms=5 +6ms
  MigrateEngine:stderr Jul 17 14:17:01.643 ERROR quaint::connector::postgres: Error in PostgreSQL connection: Error { kind: Closed, cause: None } +114ms
  MigrateEngine:stderr Jul 17 14:17:01.643  INFO InferMigrationSteps{migration_id="DUMMY_NAME"}: quaint::connector::metrics: query="\n        SELECT\n            indexInfos.relname as name,\n            columnInfos.attname AS column_name,\n            rawIndex.indisunique AS is_unique,\n            rawIndex.indisprimary AS is_primary_key,\n            tableInfos.relname AS table_name,\n            rawIndex.indkeyidx,\n            pg_get_serial_sequence(\'\"\' || $1 || \'\".\"\' || tableInfos.relname || \'\"\', columnInfos.attname) AS sequence_name\n        FROM\n            -- pg_class stores infos about tables, indices etc: https://www.postgresql.org/docs/current/catalog-pg-class.html\n            pg_class tableInfos,\n            pg_class indexInfos,\n            -- pg_index stores indices: https://www.postgresql.org/docs/current/catalog-pg-index.html\n            (\n                SELECT\n                    indrelid,\n                    indexrelid,\n                    indisunique,\n                    indisprimary,\n                    pg_index.indkey AS indkey,\n                    generate_subscripts(pg_index.indkey, 1) AS indkeyidx\n                FROM pg_index\n                GROUP BY indrelid, indexrelid, indisunique, indisprimary, indkeyidx, indkey\n                ORDER BY indrelid, indexrelid, indkeyidx\n            ) rawIndex,\n            -- pg_attribute stores infos about columns: https://www.postgresql.org/docs/current/catalog-pg-attribute.html\n            pg_attribute columnInfos,\n            -- pg_namespace stores info about the schema\n            pg_namespace schemaInfo\n        WHERE\n            -- find table info for index\n            tableInfos.oid = rawIndex.indrelid\n            -- find index info\n            AND indexInfos.oid = rawIndex.indexrelid\n            -- find table columns\n            AND columnInfos.attrelid = tableInfos.oid\n            AND columnInfos.attnum = rawIndex.indkey[rawIndex.indkeyidx]\n            -- we only consider ordinary tables\n            AND tableInfos.relkind = \'r\'\n            -- we only consider stuff out of one specific schema\n            AND tableInfos.relnamespace = schemaInfo.oid\n            AND schemaInfo.nspname = $1\n        GROUP BY tableInfos.relname, indexInfos.relname, rawIndex.indisunique, rawIndex.indisprimary, columnInfos.attname, rawIndex.indkeyidx\n        ORDER BY rawIndex.indkeyidx\n        " item_type="query" params=["public"] duration_ms=113 +0ms
  MigrateEngine:stderr {"is_panic":true,"message":"[libs/sql-schema-describer/src/postgres.rs:484:20] querying for indices: Error { kind: QueryError(Error { kind: Closed, cause: None }), original_code: None, original_message: Some(\"connection closed\") }","backtrace":"   0: backtrace::backtrace::trace\n   1: backtrace::capture::Backtrace::new\n   2: user_facing_errors::Error::new_in_panic_hook\n   3: user_facing_errors::panic_hook::set_panic_hook::{{closure}}\n   4: std::panicking::rust_panic_with_hook\n   5: _rust_begin_unwind\n   6: core::panicking::panic_fmt\n   7: core::result::unwrap_failed\n   8: <sql_schema_describer::postgres::SqlSchemaDescriber as sql_schema_describer::SqlSchemaDescriberBackend>::describe::__describe::{{closure}}\n   9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  13: <migration_core::commands::infer_migration_steps::InferMigrationStepsCommand as migration_core::commands::command::MigrationCommand>::execute::__execute::{{closure}}\n  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll\n  18: <futures_util::compat::compat03as01::Compat<Fut> as futures::future::Future>::poll\n  19: <futures::future::lazy::Lazy<F,R> as futures::future::Future>::poll\n  20: futures::future::chain::Chain<A,B,C>::poll\n  21: <futures::future::then::Then<A,B,F> as futures::future::Future>::poll\n  22: <futures::future::map::Map<A,F> as futures::future::Future>::poll\n  23: <futures::future::either::Either<A,B> as futures::future::Future>::poll\n  24: futures::task_impl::std::set\n  25: migration_engine::main::{{closure}}\n  26: tokio::runtime::enter::Enter::block_on\n  27: tokio::runtime::context::enter\n  28: tokio::runtime::handle::Handle::enter\n  29: migration_engine::main\n  30: std::rt::lang_start::{{closure}}\n  31: std::rt::lang_start_internal\n  32: _main\n"} +5ms
The above error occurred in the <TabIndexProvider> component:
    in TabIndexProvider
    in App

React will try to recreate this component tree from scratch using the error boundary you provided, App.
Warning: App: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI.
  prisma TypeError: Cannot read property 'Symbol(keypress-decoder)' of undefined
  prisma     at Object.emitKeypressEvents (readline.js:1043:13)
  prisma     at Object.useStdin (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2913327)
  prisma     at TabIndexProvider (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2313126)
  prisma     at renderWithHooks (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2706893)
  prisma     at mountIndeterminateComponent (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2736840)
  prisma     at beginWork$1 (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2752820)
  prisma     at Object._s (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2767616)
  prisma     at invokeGuardedCallback (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2770115)
  prisma     at Ou (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2812237)
  prisma     at performUnitOfWork (/Users/timleslie/src/prisma-test/node_modules/@prisma/cli/build/index.js:2:2801113) +0ms

@joelewis
Copy link
Author

joelewis commented Jul 17, 2020

Running with DEBUG="*" gives a bit more info that might be useful.

@timleslie Never knew this.

Once used, it revealed the actual error. I had a model with no unique id column and the migration was successful once I fixed my .schema file. The cause of failure should have been revealed even without the DEBUG flag.

Thanks for the tip.

@timleslie
Copy link

Tracking down the postgres logs I see the following:

2020-07-17 15:34:49.966 AEST [21615] ERROR:  relation "_Migration" already exists
2020-07-17 15:34:49.966 AEST [21615] STATEMENT:  CREATE TABLE "public"."_Migration" ("revision" SERIAL PRIMARY KEY NOT NULL, "name" TEXT NOT NULL, "datamodel" TEXT NOT NULL, "status" TEXT NOT NULL, "applied" INTEGER NOT NULL, "rolled_back" INTEGER NOT NULL, "datamodel_steps" TEXT NOT NULL, "database_migration" TEXT NOT NULL, "errors" TEXT NOT NULL, "started_at" timestamp(3) NOT NULL, "finished_at" timestamp(3));
2020-07-17 15:34:50.075 AEST [112] LOG:  server process (PID 21615) was terminated by signal 9: Killed: 9
2020-07-17 15:34:50.075 AEST [112] DETAIL:  Failed process was running: 
                SELECT
                    indexInfos.relname as name,
                    columnInfos.attname AS column_name,
                    rawIndex.indisunique AS is_unique,
                    rawIndex.indisprimary AS is_primary_key,
                    tableInfos.relname AS table_name,
                    rawIndex.indkeyidx,
                    pg_get_serial_sequence('"' || $1 || '"."' || tableInfos.relname || '"', columnInfos.attname) AS sequence_name
                FROM
                    -- pg_class stores infos about tables, indices etc: https://www.postgresql.org/docs/current/catalog-pg-class.html
                    pg_class tableInfos,
                    pg_class indexInfos,
                    -- pg_index stores indices: https://www.postgresql.org/docs/current/catalog-pg-index.html
                    (
                        SELECT
                            indrelid,
                            indexrelid,
                            indisunique,
                            indisprimary,
                            pg_index.indkey AS indkey,
                            generate_subscripts(pg_index.indkey, 1) AS indkeyidx
                        FROM pg_in
2020-07-17 15:34:50.075 AEST [112] LOG:  terminating any other active server processes
2020-07-17 15:34:50.075 AEST [21585] WARNING:  terminating connection because of crash of another server process
2020-07-17 15:34:50.075 AEST [21585] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-07-17 15:34:50.075 AEST [21585] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2020-07-17 15:34:50.077 AEST [112] LOG:  all server processes terminated; reinitializing
2020-07-17 15:34:50.085 AEST [21616] LOG:  database system was interrupted; last known up at 2020-07-17 15:33:42 AEST
2020-07-17 15:34:50.259 AEST [21616] LOG:  database system was not properly shut down; automatic recovery in progress
2020-07-17 15:34:50.263 AEST [21616] LOG:  redo starts at 9/811F43D8
2020-07-17 15:34:50.265 AEST [21616] LOG:  redo done at 9/81231A68
2020-07-17 15:34:50.283 AEST [112] LOG:  database system is ready to accept connections

This suggests the the query causing the issue is in libs/sql-schema-describer/src/postgres.rs at line 434 with the query:

        SELECT
            indexInfos.relname as name,
            columnInfos.attname AS column_name,
            rawIndex.indisunique AS is_unique,
            rawIndex.indisprimary AS is_primary_key,
            tableInfos.relname AS table_name,
            rawIndex.indkeyidx,
            pg_get_serial_sequence('"' || $1 || '"."' || tableInfos.relname || '"', columnInfos.attname) AS sequence_name
        FROM
            -- pg_class stores infos about tables, indices etc: https://www.postgresql.org/docs/current/catalog-pg-class.html
            pg_class tableInfos,
            pg_class indexInfos,
            -- pg_index stores indices: https://www.postgresql.org/docs/current/catalog-pg-index.html
            (
                SELECT
                    indrelid,
                    indexrelid,
                    indisunique,
                    indisprimary,
                    pg_index.indkey AS indkey,
                    generate_subscripts(pg_index.indkey, 1) AS indkeyidx
                FROM pg_index
                GROUP BY indrelid, indexrelid, indisunique, indisprimary, indkeyidx, indkey
                ORDER BY indrelid, indexrelid, indkeyidx
            ) rawIndex,
            -- pg_attribute stores infos about columns: https://www.postgresql.org/docs/current/catalog-pg-attribute.html
            pg_attribute columnInfos,
            -- pg_namespace stores info about the schema
            pg_namespace schemaInfo
        WHERE
            -- find table info for index
            tableInfos.oid = rawIndex.indrelid
            -- find index info
            AND indexInfos.oid = rawIndex.indexrelid
            -- find table columns
            AND columnInfos.attrelid = tableInfos.oid
            AND columnInfos.attnum = rawIndex.indkey[rawIndex.indkeyidx]
            -- we only consider ordinary tables
            AND tableInfos.relkind = 'r'
            -- we only consider stuff out of one specific schema
            AND tableInfos.relnamespace = schemaInfo.oid
            AND schemaInfo.nspname = $1
        GROUP BY tableInfos.relname, indexInfos.relname, rawIndex.indisunique, rawIndex.indisprimary, columnInfos.attname, rawIndex.indkeyidx
        ORDER BY rawIndex.indkeyidx

Running this query from within psql gives:

server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

@timleslie
Copy link

I spun up a completely brand new database and re-ran the init migration and everything works fine.

I'm concluding that the database I have been using for testing has somehow become internally corrupted, which is what's causing the obscure failures.

The original problem described in this issue regarding <TabIndexProvider> still stands, as it would be useful to have the panic message displayed correctly, but I think I'm now unblocked by using the new, non-corrupted DB 👍

Thanks @joelewis for letting me know that you were able to get migrate to work after seeing the error and fixing your schema, it helped point me towards something unique in my setup, rather than something wrong in the core of prisma 👍

@janpio janpio transferred this issue from prisma/prisma Jul 18, 2020
@djstein
Copy link

djstein commented Jul 21, 2020

bumping as I am also experiencing this when upgrading to 2.2.2 from 2.2.0 today

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. topic: tabindexprovider
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants