-
Notifications
You must be signed in to change notification settings - Fork 0
50 feat parse tables with relationship #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Schema Post-Processing | ||
|
|
||
| After all AL files are parsed, `IDBMLWriter.WriteDBMLAsync` passes the `OutputSchema` through `ISchemaPostProcessor` before generating DBML output. The post-processor works on a **deep copy** of the schema and never mutates the original. | ||
|
|
||
| ## Pipeline | ||
|
|
||
| The steps run in this order: | ||
|
|
||
| ``` | ||
| 1. InferSinglePkWhenOnlyUnknownPlusOneColumn | ||
| 2. RemoveEmptyTables | ||
| 3. CreateStubsForMissingReferencedTables | ||
| 4. AddMissingReferencedFieldsToExistingTables | ||
| 5. Build singlePkByTable | ||
| 6. ResolveUnknownFieldReferences | ||
| 7. RemoveUnknownFieldColumns | ||
| ``` | ||
|
|
||
| ## UnknownField convention | ||
|
|
||
| When a `TableRelation` specifies no field (e.g. `TableRelation = Vendor;`), the field name is set to the sentinel value `"UnknownField"`. This signals to the post-processor that the actual target field is unknown and should be resolved from the target table's primary key if possible. | ||
|
|
||
| ## Step details | ||
|
|
||
| **1. InferSinglePkWhenOnlyUnknownPlusOneColumn** | ||
| If a table has exactly one real field and one `UnknownField` placeholder, and no PK is declared, the real field is inferred as the primary key. This handles partially parsed tables that lack an explicit `key(PK; ...)` declaration. | ||
|
|
||
| **2. RemoveEmptyTables** | ||
| Tables with no fields are removed. These are typically side effects of a `tableextension` file being parsed when the base table AL file is not in the input — the base table gets created as an empty shell and is not useful in the output. | ||
|
|
||
| **3. CreateStubsForMissingReferencedTables** | ||
| For each `TableRelation` reference pointing to a table absent from the schema, a stub table is created: | ||
| - If the reference includes an explicit field name: the stub contains that field as PK. | ||
| - If only `UnknownField` references exist: the stub contains an `UnknownField` column as PK (typed from the referencing field). The relation is kept as-is in the output — the schema is technically incomplete but the reference is not broken. | ||
|
|
||
| **4. AddMissingReferencedFieldsToExistingTables** | ||
| For tables that exist (e.g. from a `tableextension`) but are missing a field that is explicitly referenced by a `TableRelation`, the missing field is added as PK at position 0. This covers the case where the base table AL file is absent but the extension file was parsed. | ||
|
|
||
| **5–7. Resolve and clean** | ||
| - `singlePkByTable` indexes all tables with exactly one primary key field. | ||
| - `ResolveUnknownFieldReferences` replaces `UnknownField` with the actual PK name for any table in that index. It also aligns the type of the referencing field with the PK's type. | ||
| - `RemoveUnknownFieldColumns` removes `UnknownField` placeholder columns from resolved tables, unless the column is itself the PK (stub tables where the target PK remains unknown). | ||
|
|
||
| ## Risks and limitations | ||
|
|
||
| | Situation | Behaviour | | ||
| |---|---| | ||
| | Target table has multiple PKs | `UnknownField` is not resolved and remains in output | | ||
| | Target table absent, no explicit field in `TableRelation` | Stub created with `UnknownField [pk]`; schema is incomplete | | ||
| | Referenced field is not the actual PK (edge case) | Stub or partial table marks a non-PK field as PK; schema is incorrect for that relation | | ||
| | Conditional `TableRelation` (`if/else`) | Relation not parsed; no reference generated | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This references “ARCHITECTURE.md — Schema post-processing”, but
docs/ARCHITECTURE.mdcurrently doesn’t contain a matching section/header (and the detailed write-up is inSCHEMA_POST_PROCESSING.md). Update the link/wording to point at the correct document/anchor or add the referenced section to ARCHITECTURE.md.