CodeGen fails on PostgreSQL in seedLegacyHierarchyConfiguration: column "ROUTINE_SCHEMA" does not exist

Abierto Apto para principiantes
#6,947 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
postgresql, sql, typescript
Área
database

Línea de trabajo

La consulta que falla está en seedLegacyHierarchyConfiguration en packages/CodeGenLib/src/Database/manage-metadata.ts, y su entrecomillado de identificadores viene de packages/SQLDialect/src/postgresqlAutoQuote.ts. Empieza por la lista fija de nombres en mayúsculas sin comillas que hay allí y comprueba si ROUTINE_SCHEMA, ROUTINE_NAME y ROUTINE_TYPE deben estar en ella. Está terminado cuando la consulta devuelve filas en PostgreSQL con esos nombres sin comillas y pasa una prueba que ejecuta el texto de la consulta por AutoQuotePostgreSQLIdentifiers y comprueba que ningún nombre ROUTINE_ queda entre comillas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Version: 6.2.2 (LTS). The same code is on the next branch.
Database: PostgreSQL 16.

What happens

mj codegen ends with a failure on PostgreSQL when an application schema has a foreign key that points to its own table. The log shows:

Error seeding legacy hierarchy configuration: column "ROUTINE_SCHEMA" does not exist
Error seeding hierarchy configuration for legacy self-referencing foreign keys
MANAGE_METADATA: Metadata management reported a failure; see the errors logged above
CodeGen finished with 1 failure

The other CodeGen stages complete, but the command exits with an error code. A pipeline that commits the generated code only after a successful CodeGen step stops here.

Cause

The function seedLegacyHierarchyConfiguration in packages/CodeGenLib/src/Database/manage-metadata.ts runs this query through runQuery, which applies the PostgreSQL identifier quoting:

SELECT ROUTINE_SCHEMA AS "RoutineSchema", ROUTINE_NAME AS "RoutineName" FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION' AND LOWER(ROUTINE_NAME) LIKE '%root%id'

The quoting in packages/SQLDialect/src/postgresqlAutoQuote.ts keeps a fixed list of upper-case names bare. The list has INFORMATION_SCHEMA and ROUTINES, but it does not have ROUTINE_SCHEMA, ROUTINE_NAME or ROUTINE_TYPE. The result of AutoQuotePostgreSQLIdentifiers is:

SELECT "ROUTINE_SCHEMA" AS "RoutineSchema", "ROUTINE_NAME" AS "RoutineName" FROM INFORMATION_SCHEMA.ROUTINES WHERE "ROUTINE_TYPE" = 'FUNCTION' AND LOWER("ROUTINE_NAME") LIKE '%root%id'

PostgreSQL has these columns in lower case, so the quoted names are not found.

Why it does not show on each install

  • SQL Server does not have the problem.
  • The function returns before this query when there is no self-referencing foreign key outside the core schema. A PostgreSQL install with no such field does not reach the query.

Steps to reproduce

  • Use a PostgreSQL database on 6.2.2.
  • Have one table in an application schema with a foreign key to its own primary key, with entity metadata for it.
  • Run mj codegen.

Suggested correction

One of these:

  • Write the three column names in lower case in the query. The quoting does not change lower-case names. We use this as a local patch, and the query then returns the correct rows.
  • Add ROUTINE_SCHEMA, ROUTINE_NAME and ROUTINE_TYPE to the list of bare names in postgresqlAutoQuote.ts.

A test that runs the query text through AutoQuotePostgreSQLIdentifiers and checks that no ROUTINE_ name is in quotes would catch this.

Lenguaje dominante
TSQL
Estrellas
32
Forks
7
Merge medio
1 d 16 h
PR fusionados (30 d)
504

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MemberJunction/MJ

Todos los issues de MemberJunction/MJ

Issues similares

Más issues de Databases

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.