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

Aperta Adatta ai principianti
#6,947 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, sql, typescript
Ambito
database

Direzione di ricerca

La query che fallisce si trova in seedLegacyHierarchyConfiguration in packages/CodeGenLib/src/Database/manage-metadata.ts, e il quoting degli identificatori deriva da packages/SQLDialect/src/postgresqlAutoQuote.ts. Inizia dalla lista fissa di nomi maiuscoli non quotati presente lì e verifica se ROUTINE_SCHEMA, ROUTINE_NAME e ROUTINE_TYPE debbano farne parte. Il lavoro è completo quando la query restituisce righe su PostgreSQL con questi nomi non quotati e un test passa eseguendo il testo della query attraverso AutoQuotePostgreSQLIdentifiers e verificando che nessun nome ROUTINE_ risulti quotato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TSQL
Stelle
32
Fork
7
Merge medio
1g 16h
PR unite (30g)
504

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MemberJunction/MJ

Tutte le issue di MemberJunction/MJ

Issue simili

Altre issue su Databases

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.