Repository navigation
feat: add numeric_precision/scale and seq_in_fk for DDL type fidelity (#142) - #143
Open
aesslinger wants to merge 1 commit into
Open
aesslinger wants to merge 1 commit into
aesslinger wants to merge 1 commit into
Conversation
…#142) Adds three new optional fields to the plugin's get_columns and get_foreign_keys responses so Tabularis generates DDL with correct type modifiers and composite FK column order (Tabularis #840, PR #939): get_columns / get_view_columns / get_all_columns_batch: - Added c.numeric_precision and c.numeric_scale to all three information_schema.columns queries. - row_to_table_column extracts them as Option<i32> and includes them as optional JSON fields (only when present, matching the character_maximum_length pattern). Without these, numeric(10,2) columns generate as bare numeric in CREATE TABLE DDL. get_foreign_keys / get_all_foreign_keys_batch: - Changed unnest(con.conkey, con.confkey) to WITH ORDINALITY to get key_seq — the true composite-key column order, independent of raw attnum. Changed ORDER BY from cols.src_attnum to cols.key_seq. - row_to_foreign_key extracts key_seq as Option<i64>, narrows to Option<i32>, and includes seq_in_fk as an optional JSON field. Without this, composite FK columns may be in the wrong order in generated DDL. All fields are additive (optional, omitted when absent) — the current host ignores unknown fields and the PR #939 host uses null-safe checks, so this is safe to ship before or after #939 lands. Verified: 400 unit tests green, 3 live tests green, 30 live_db tests green, 83/83 cross-repo parity suite unchanged, clippy + fmt clean. Manual verification: numeric(10,2) → prec=10 scale=2, composite FK (y,x) → seq_in_fk=1,2 ordered by constraint definition.
Version suggestionBased on this PR's title (
This is informational only — no tag or release is created automatically yet. |
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.
Summary
Fixes #142. Adds three new optional fields to the plugin's
get_columnsandget_foreign_keysresponses so Tabularis generates DDL with correct type modifiers (numeric(10,2)instead of barenumeric) and composite foreign key column order. Companion to Tabularis PR #939 ("fix: restore type fidelity in Generate SQL / Create Table (#840)").All fields are additive (optional, omitted when absent) — safe to ship before or after #939 lands. Verified empirically that the current host (without #939) ignores the extra fields (serde's default: no
deny_unknown_fields).Changes
get_columns/get_view_columns/get_all_columns_batch(3 SQL queries)c.numeric_precisionandc.numeric_scaleto all threeinformation_schema.columnsqueriesrow_to_table_columnextracts them asOption<i32>and includes them as optional JSON fields (only when present — matching thecharacter_maximum_lengthpattern)get_foreign_keys/get_all_foreign_keys_batch(2 SQL queries)unnest(con.conkey, con.confkey) AS cols(src_attnum, ref_attnum)toWITH ORDINALITY AS cols(src_attnum, ref_attnum, key_seq)— the true composite-key column order, independent of raw attnumcols.key_seqto the SELECT; changedORDER BYfromcols.src_attnumtocols.key_seqrow_to_foreign_keyextractskey_seqasOption<i64>, narrows toOption<i32>, and includesseq_in_fkas an optional JSON fieldFK field names — already compatible
The plugin already uses
name,ref_table,ref_column(the names PR #939's PLUGIN_GUIDE.md documents). No rename needed.Verification
cargo fmt --check+cargo clippy --all-targets -- -D warningslive_dbsuiteManual end-to-end verification
numeric(10,2)→numeric_precision=10, numeric_scale=2numeric(5)→numeric_precision=5, numeric_scale=0numeric(no precision) → fields omittedvarchar/text/boolean/timestamptz→ fields omitted(y, x) REFERENCES (b, a)→seq_in_fk=1fory,seq_in_fk=2forxseq_in_fk=1Compatibility
deny_unknown_fields— verified empirically with a test against the actualTableColumn/ForeignKeystructs onTabularisDB/main)sqlGenerator.tsuses null-safe checks (column.numeric_precision != null,column.numeric_scale ?? 0,a.seq_in_fk ?? Number.MAX_SAFE_INTEGER)