Integration metadata can't declare descriptions on refresh, ExtendedType, joined fields or organic keys

Aperta
#6,872 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à
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
sql, typescript
Ambito
backend, databases

Direzione di ricerca

This is four separate design changes across the schema builder and CodeGen, so pick one gap rather than the whole issue. Start by reading packages/Integration/schema-builder/src/SchemaBuilder.ts:109-129 and its DDLGenerator.ts:243 to see the evolution path, then IntegrationDiscoveryResolver.ts:2250-2854 for how metadata becomes table definitions, and manage-metadata.ts:6357-6425 for soft-FK application. Done means descriptions, ExtendedType, joined fields or organic keys survive both first create and refresh, verified against the rasa.io connector.

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

Descrizione

Summary

A connector's metadata (MJ: Integration Objects and MJ: Integration Object Fields) is the one place that knows what its data means: which column is an email, which ID links to which table, and how the same person shows up in several tables. Today little of that reaches the entities MJ builds from it, so every install needs hand work afterwards before the tables are useful to agents, queries and DBAutoDoc. Four gaps, all on next (d7a630ca9d):

  1. Descriptions reach the database only when a table is first created. A schema refresh never writes them.
  2. There is no way to set ExtendedType (for example Email) on a field from integration metadata.
  3. Foreign keys from integration metadata never get a joined ("virtual") column from the related entity, and the link always targets the parent's first primary-key column.
  4. Integration metadata cannot declare organic keys.

In-process (RSU) CodeGen turns the AI generation steps off unless RSU_CODEGEN_ADVANCED_GENERATION=1 (packages/CodeGenLib/src/Config/config.ts:1774, ApplyInProcessAdvancedGenerationPolicy at 1789). That is a sensible default, but it means the only things set on an integration install are what the metadata states directly. The examples below use the rasa.io connector, whose tables (Contact, Newsletter Contact, Newsletter Action, Contact External Identifier, topics) all link to one contact ID that carries the email.

1. Descriptions don't reach existing installs

On first create, IntegrationObject.Description and IntegrationObjectField.Description flow through the resolver (packages/MJServer/src/resolvers/IntegrationDiscoveryResolver.ts:2250, :2287, :2827) into the table definition, and the create DDL writes MS_Description / COMMENT ON for the table and each column (packages/SchemaEngine/src/DDLGenerator.ts:156, GenerateDescriptions at 169). CodeGen then copies those into Entity.Description and EntityField.Description, and keeps them in sync while AutoUpdateDescription is on.

A table that already exists takes the evolution path instead (packages/Integration/schema-builder/src/SchemaBuilder.ts:109-129). SchemaEvolution.GenerateEvolutionMigration and GenerateAlterTableAddColumn (packages/Integration/schema-builder/src/DDLGenerator.ts:243) only add or alter columns and indexes. Neither writes a description. So:

  • a column added by a later connector version has no description;
  • a description improved in a later connector version never reaches the database or the entity.

Suggested fix: in the evolution path, emit CommentOnColumn for added columns, and update the table and column comments when the catalog text differs from the current extended property. CodeGen's existing AutoUpdateDescription sync then carries it to the entity, and a description someone edited by hand in MJ stays protected by that flag.

2. No way to set ExtendedType from integration metadata

MJIntegrationObjectFieldSchema (packages/MJCoreEntities/src/generated/schemas/__mj.ts:26598) has no ExtendedType and no IsNameField, and neither does the per-connection MJCompanyIntegrationObjectFieldSchema (:13812). Nothing under packages/Integration or packages/SchemaEngine references ExtendedType, and TargetColumnConfig (packages/Integration/schema-builder/src/interfaces.ts:61-80) has nowhere to carry it.

The only CodeGen step that sets EntityField.ExtendedType is the AI form-layout pass, which is off under RSU and only touches new fields. A connector that knows email is an email address has no way to say so. Today the customer sets ExtendedType='Email' and AutoUpdateExtendedType=0 on each field by hand after install, and features that look for email fields (list builders that need an "emailable" entity, for example) don't see these tables until then.

Suggested fix: let an Integration Object Field declare ExtendedType, carry it through TargetColumnConfig into the per-field additionalSchemaInfo entry, and have CodeGen apply it the same way it applies other declared field settings (respecting AutoUpdateExtendedType).

3. Joined fields for integration foreign keys

RelatedIntegrationObjectID becomes a soft FK, but:

  • The target column is never the one the metadata names. The resolver hardcodes TargetField: 'ID' (IntegrationDiscoveryResolver.ts:2854), and SoftFKConfigEmitter links to the parent's first primary-key column (packages/Integration/schema-builder/src/SoftFKConfigEmitter.ts:152). RelatedIntegrationObjectFieldName is ignored. For a parent with a two-column key (rasa's Newsletter Contact is newsletter_id + id), a child is silently linked to newsletter_id alone, and any join on it multiplies rows.
  • The link never gets a joined column. CodeGen sets IncludeRelatedEntityNameFieldInBaseView only when it inserts a field that already has a hard FK (packages/CodeGenLib/src/Database/manage-metadata.ts:7009). Integration columns are inserted before soft FKs are applied, and the soft-FK update (applySoftForeignKeys, :6357, update at about :6419-6425) doesn't set the flag. The base view only joins fields with that flag or a RelatedEntityJoinFields config (packages/CodeGenLib/src/Database/sql_codegen.ts:3918).
  • Even with the flag on, the alias would collide for snake_case keys: stripID strips only an uppercase ID suffix (sql_codegen.ts:4090-4095), so contact_id maps to itself and the column becomes contact_id_Virtual.

The case that matters is a single-column link to a unique target, for example contact_id on an action or topics table pointing at Contact.id. With a joined email column on each of those tables, the email is one column away instead of a hand-written join. EntityField.RelatedEntityJoinFields ({"mode":"override","fields":[{"field":"email","alias":"ContactEmail"}]}) already does exactly this, but only as a setting made by hand after install.

Suggested fix:

  • Honor RelatedIntegrationObjectFieldName as the FK target, and refuse (with a warning) a link to one column of a multi-column key instead of linking to the first PK column.
  • Let an Integration Object Field declare the joined fields for its link (same shape as RelatedEntityJoinFields), and write that onto the EntityField when the soft FK is applied.
  • Make stripID handle a _id / _ID suffix.

4. Organic keys can't be declared

Organic keys (MJ: Entity Organic Keys, MJ: Entity Organic Key Related Entities) are created by CodeGen from an OrganicKeys array in additionalSchemaInfo (extractOrganicKeysFromConfig, manage-metadata.ts:1206; processOrganicKeyConfig, :1330).

The integration schema builder never writes that array. Its table entries carry only PrimaryKey and ForeignKeys (SoftFKConfigEmitter.ts:8-17). The closest thing, IsUniqueKey on a non-key field, becomes OrganicKeyFields (SchemaBuilder.ts:315), which only produces an index IX_<schema>_<table>_OK_<col> (packages/SchemaEngine/src/DDLGenerator.ts:123-129) and no organic key rows.

DBAutoDoc doesn't fill the gap here. It doesn't read ExtendedType, and it drops a detected concept unless one of its columns is a primary key (packages/DBAutoDoc/src/discovery/OrganicKeyTranslator.ts), so an email that is never a key column isn't proposed. The connector knows the answer up front ("email on Contact identifies a person, and it matches email on these other tables"), and it should be able to say so.

Suggested fix: let an Integration Object declare organic keys (name, match fields, normalization such as LowerCaseTrim, related objects and their fields), and have the schema builder translate them into OrganicKeys entries for the tables it builds, using the derived schema and table names. CodeGen's existing processing does the rest.

Suggested shape

One option that needs no new columns: a documented block in the existing Configuration JSON on Integration Object Field and Integration Object, for example:

// Integration Object Field: Contact.email
{ "entityField": { "ExtendedType": "Email" } }

// Integration Object Field: Newsletter Action.contact_id
{ "entityField": { "RelatedEntityJoinFields": { "mode": "override", "fields": [{ "field": "email", "alias": "ContactEmail" }] } } }

// Integration Object: Contact
{ "organicKeys": [{ "Name": "Email", "MatchFieldNames": ["email"], "NormalizationStrategy": "LowerCaseTrim",
    "RelatedObjects": [{ "Object": "Newsletter Contact", "FieldNames": ["email"] }] }] }

New columns (ExtendedType on Integration Object Field, for example) would work as well and are easier to validate. Either way, the important part is that the schema builder passes these through on both first create and refresh.

Related, smaller

  • Shipped queries: a connector can already ship approved MJ: Queries in its metadata. They have to take the schema as a parameter ({{ IntegrationSchema | default('rasa') | sqlIdentifier }}), because nothing resolves an integration's table to schema.view at run time, and a query shipped before its tables exist isn't re-extracted after the apply. A run-time token for an integration's schema, or re-extraction after apply, would make these simpler.
  • Integration/docs/schema-management.md says the generated views include joins for related records. Per #3 they don't for integration FKs; the doc should match whichever behavior ships.
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 Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.