Repository navigation
Script parser: honour column-level constraints and non-null primary keys - #25
Merged
Merged
Conversation
A primary key or foreign key declared on a column (Id int primary key, ParentId int references Parent(Id)) was ignored when reading a SQL script, so the column had no pk marker and the relationship was missing. Column-level constraints are now processed for both create table and alter table add. A primary key column is never nullable, so a table-level primary key(Id) no longer renders its column as (nullable).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two fixes to how
ScriptParserreads a SQL script. Diagrams read from a live database throughSchemaReaderwere already correct; these bring the script path in line.Column-level constraints were ignored
Only table-level constraints were processed, so anything declared on the column itself was dropped:
rendered both
Idcolumns withoutpk, and with noParent ||--o{ Childrelationship. Column constraints now go through the same handling as table constraints, for bothcreate tableandalter table ... add. Named and unnamed forms both work.Table-level primary key columns rendered as nullable
rendered
int(nullable) Id pk. A primary key column is never nullable, soTableBuildernow marks every primary key column as not null when the table is built, however the key was declared. That replaces the inline-only check that was inScriptParser.IsNullable.Tests
RenderMarkdownFromScriptWithColumnLevelConstraintscovers a named inline primary key, a primary key column added byalter table, and named and unnamed inline foreign keys.pkon inline primary key columns. InRenderMarkdownFromScriptWithTableLevelPrimaryKey,Child.IdgainspkandParent.Idchanges fromint(nullable) Id pktoint Id pk.SqlServerToMermaidTool.Tests, which CI does not run; they pass locally.