Skip fieldless custom types when exporting to SQL Server - #1146
Merged
Merged
Conversation
type.fields.length < 0 can never be true -- Array length is unsigned -- so the guard meant to protect the type.fields[0] access was dead and the else branch always ran. A custom type with no fields passed undefined into getTypeString, whose MSSQL branch reads field.type, and the export threw. A new type starts out that way: addType() creates it with fields: [], so opening the Types tab and exporting to SQL Server before adding a field is enough. Drop those types instead -- CREATE TYPE has nothing to derive from without a field.
|
@NgoQuocViet2001 is attempting to deploy a commit to the dottle's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Humanish project operator check (automated): I exercised File → Export SQL → MSSQL on local production builds of
Both production builds passed using their committed lockfiles. The requested base/head also differ in the js-yaml lock entry (4.3.2/4.3.1). This checks the browser export path; I did not execute the SQL against SQL Server. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Problem
tablesToSQLServerguards the first-field access with a comparison that can never be true:Array.prototype.lengthis never negative, so theelsebranch always runs. For a custom type with no fields,type.fields[0]isundefined, andgetTypeString's MSSQL branch starts withlet type = field.type;.How it is reached
A new custom type starts out exactly like that —
addType()insrc/context/TypesContext.jsxcreates it with no starter field:So opening the Types tab, adding a type, and choosing Export source → MSSQL before giving it a field is enough. Exporting a generic diagram with that type:
In the editor this surfaces as an export that silently produces nothing, since the menu handler calls
jsonToSQLServerwithout a try/catch.Fix
Drop fieldless types before mapping, and remove the dead ternary the filter replaces.
CREATE TYPE ... FROMneeds a base type, and a fieldless type has none to offer, so there is nothing valid to emit for it.Test plan
jsonToSQLServer(bundled with esbuild, since the module uses extensionless imports) against a generic diagram containing one table, one fieldless type and one type with aDECIMALfield:TypeErroraboveCREATE TYPE [money_t] FROM DECIMAL;for the populated type, skips the empty one, and the table follows unchangednpm run lint→ clean.