diff --git a/schema-engine/sql-introspection-tests/tests/enums/cockroachdb.rs b/schema-engine/sql-introspection-tests/tests/enums/cockroachdb.rs index d873700a6422..426059beeffa 100644 --- a/schema-engine/sql-introspection-tests/tests/enums/cockroachdb.rs +++ b/schema-engine/sql-introspection-tests/tests/enums/cockroachdb.rs @@ -287,3 +287,47 @@ async fn an_enum_with_invalid_value_names_should_have_them_commented_out(api: &m api.expect_datamodel(&expected).await; Ok(()) } + +// Regression: https://github.com/prisma/prisma/issues/22456 +#[test_connector(tags(CockroachDb))] +async fn enum_array_type(api: &mut TestApi) -> TestResult { + let setup = indoc! {r#" + CREATE TYPE "_foo" AS ENUM ('FIRST', 'SECOND'); + + CREATE TABLE "Post" ( + "id" TEXT NOT NULL, + "contentFilters" "_foo"[], + CONSTRAINT "Post_pkey" PRIMARY KEY ("id") + ); + "#}; + + api.raw_cmd(setup).await; + + let expectation = expect![[r#" + generator client { + provider = "prisma-client-js" + } + + datasource db { + provider = "cockroachdb" + url = "env(TEST_DATABASE_URL)" + } + + model Post { + id String @id + contentFilters foo[] + } + + enum foo { + FIRST + SECOND + + @@map("_foo") + } + "#]]; + + api.expect_datamodel(&expectation).await; + api.expect_no_warnings().await; + + Ok(()) +} diff --git a/schema-engine/sql-introspection-tests/tests/enums/postgres.rs b/schema-engine/sql-introspection-tests/tests/enums/postgres.rs index 402d7300e0de..c03e65baf18c 100644 --- a/schema-engine/sql-introspection-tests/tests/enums/postgres.rs +++ b/schema-engine/sql-introspection-tests/tests/enums/postgres.rs @@ -341,3 +341,47 @@ async fn a_mapped_enum_will_not_warn(api: &mut TestApi) -> TestResult { Ok(()) } + +// Regression: https://github.com/prisma/prisma/issues/22456 +#[test_connector(tags(Postgres), exclude(CockroachDb))] +async fn enum_array_type(api: &mut TestApi) -> TestResult { + let setup = indoc! {r#" + CREATE TYPE "_foo" AS ENUM ('FIRST', 'SECOND'); + + CREATE TABLE "Post" ( + "id" TEXT NOT NULL, + "contentFilters" "_foo"[], + CONSTRAINT "Post_pkey" PRIMARY KEY ("id") + ); + "#}; + + api.raw_cmd(setup).await; + + let expectation = expect![[r#" + generator client { + provider = "prisma-client-js" + } + + datasource db { + provider = "postgresql" + url = "env(TEST_DATABASE_URL)" + } + + model Post { + id String @id + contentFilters foo[] + } + + enum foo { + FIRST + SECOND + + @@map("_foo") + } + "#]]; + + api.expect_datamodel(&expectation).await; + api.expect_no_warnings().await; + + Ok(()) +} diff --git a/schema-engine/sql-schema-describer/src/postgres.rs b/schema-engine/sql-schema-describer/src/postgres.rs index d7ea250b4bba..fe7b86f7c9be 100644 --- a/schema-engine/sql-schema-describer/src/postgres.rs +++ b/schema-engine/sql-schema-describer/src/postgres.rs @@ -1615,7 +1615,7 @@ fn get_column_type_postgresql(row: &ResultRow, schema: &SqlSchema) -> ColumnType let enum_id: Option<_> = match data_type.as_str() { "ARRAY" if full_data_type.starts_with('_') => { let namespace = row.get_string("type_schema_name"); - schema.find_enum(full_data_type.trim_start_matches('_'), namespace.as_deref()) + schema.find_enum(&full_data_type[1..], namespace.as_deref()) } _ => { let namespace = row.get_string("type_schema_name"); @@ -1709,7 +1709,7 @@ fn get_column_type_cockroachdb(row: &ResultRow, schema: &SqlSchema) -> ColumnTyp let enum_id: Option<_> = match data_type.as_str() { "ARRAY" if full_data_type.starts_with('_') => { let namespace = row.get_string("type_schema_name"); - schema.find_enum(full_data_type.trim_start_matches('_'), namespace.as_deref()) + schema.find_enum(&full_data_type[1..], namespace.as_deref()) } _ => { let namespace = row.get_string("type_schema_name");