Integration metadata can't declare descriptions on refresh, ExtendedType, joined fields or organic keys
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
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):
- Descriptions reach the database only when a table is first created. A schema refresh never writes them.
- There is no way to set
ExtendedType(for exampleEmail) on a field from integration metadata. - 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.
- 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), andSoftFKConfigEmitterlinks to the parent's first primary-key column (packages/Integration/schema-builder/src/SoftFKConfigEmitter.ts:152).RelatedIntegrationObjectFieldNameis ignored. For a parent with a two-column key (rasa's Newsletter Contact isnewsletter_id + id), a child is silently linked tonewsletter_idalone, and any join on it multiplies rows. - The link never gets a joined column. CodeGen sets
IncludeRelatedEntityNameFieldInBaseViewonly 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 aRelatedEntityJoinFieldsconfig (packages/CodeGenLib/src/Database/sql_codegen.ts:3918). - Even with the flag on, the alias would collide for snake_case keys:
stripIDstrips only an uppercaseIDsuffix (sql_codegen.ts:4090-4095), socontact_idmaps to itself and the column becomescontact_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
RelatedIntegrationObjectFieldNameas 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
stripIDhandle a_id/_IDsuffix.
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: Queriesin its metadata. They have to take the schema as a parameter ({{ IntegrationSchema | default('rasa') | sqlIdentifier }}), because nothing resolves an integration's table toschema.viewat 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.mdsays 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MemberJunction/MJ
-
DBAutoDoc: export --state-file writes SQL Server SQL for a PostgreSQL database, ignoring --providerAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
MemberJunction/MJ#7094 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
MemberJunction/MJ#6971 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MemberJunction/MJ#6947 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MemberJunction/MJ#6800 ·
I maintainer di solito rispondono entro 1 giorno
-
Convention: saved-query discoverability follows Status — Approved is canon, Pending is a draftAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MemberJunction/MJ#6746 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MemberJunction/MJ
Issue simili
-
HXsetdir strdup leakAperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
-
funding: failure logs print `<nil>` error and zero channel IDForse già presa @litbot-9000 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
lightningnetwork/lnd#11676 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Fei2411/DeepSeek-Bot#2891 ·
-
factory:subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno