Repository navigation
Description
Problem
Tabularis PR #939
("fix: restore type fidelity in Generate SQL / Create Table (#840)") adds
three new optional fields to the host's TableColumn and ForeignKey
models so that generated CREATE TABLE DDL preserves type modifiers
like numeric(10,2) and composite foreign key column order.
The plugin does not currently return these fields, so:
numeric(10,2)columns generate as barenumeric(missing
precision/scale)- Composite foreign keys may have columns in the wrong order (the host
falls back to row order instead ofseq_in_fk)
What PR #939 adds
get_columns — numeric_precision and numeric_scale
New optional TableColumn fields (Option<i32>, skip_serializing_if = Option::is_none):
{
"name": "price",
"data_type": "numeric",
"character_maximum_length": null,
"numeric_precision": 10,
"numeric_scale": 2,
...
}The host's sqlGenerator.ts uses them: if (!hasModifier && column.numeric_precision != null) { const scale = column.numeric_scale ?? 0; return \${type}(${column.numeric_precision},${scale})`; }`. Without
them, it falls back to the bare type name.
The builtin's get_columns query now selects c.numeric_precision and
c.numeric_scale from information_schema.columns. The plugin's query
already selects c.character_maximum_length but not these two fields.
get_foreign_keys — seq_in_fk
New optional ForeignKey field (Option<i32>, skip_serializing_if = Option::is_none):
{
"name": "fk_comp",
"column_name": "a",
"ref_table": "ref_t",
"ref_column": "x",
"seq_in_fk": 1,
...
}For composite FKs, the host groups entries by name and orders by
seq_in_fk (falling back to row order when absent). Without it,
composite FK columns may be in the wrong order in generated DDL.
The builtin's FK query now uses WITH ORDINALITY on
unnest(con.conkey, con.confkey) to get key_seq (the true composite-key
column order, independent of raw attnum) and orders by it. The plugin's
query uses plain unnest without WITH ORDINALITY.
FK field names — already compatible
PR #939's PLUGIN_GUIDE.md uses name, ref_table, ref_column. The
plugin already uses these names — no change needed.
Can the plugin ship this before #939 lands?
Yes. All three fields are purely additive:
- The host's Rust models use
Option<T>with#[serde(skip_serializing_if = "Option::is_none")]— absent fields deserialize fine. - The TypeScript
sqlGenerator.tsuses null-safe checks
(column.numeric_precision != null,column.numeric_scale ?? 0,
a.seq_in_fk ?? Number.MAX_SAFE_INTEGER) — absent fields fall back to
current behavior. - The current host (without #939) ignores unknown JSON fields — returning
extra fields is safe. - When #939 lands, the host picks up the new fields automatically.
There is no dependency ordering requirement. The plugin can ship this
before or after #939.
Suggested implementation
get_columns (+ get_all_columns_batch, get_view_columns)
- Add
c.numeric_precisionandc.numeric_scaleto the SQL query in
fetch_table_columns(and the batch/view query variants). - Extract them in
row_to_table_columnasOption<i32>. - Include them as optional fields in the JSON response (only when
present, matchingcharacter_maximum_length's conditional-insert
pattern).
get_foreign_keys (+ get_all_foreign_keys_batch)
- Change
unnest(con.conkey, con.confkey) AS cols(src_attnum, ref_attnum)
toWITH ORDINALITY AS cols(src_attnum, ref_attnum, key_seq). - Add
cols.key_seqto the SELECT. - Change
ORDER BY ... cols.src_attnumtoORDER BY ... cols.key_seq. - Extract
key_seqasOption<i64>and narrow toOption<i32>. - Include
seq_in_fkin the JSON response inrow_to_foreign_key.
Parity
The builtin's get_columns and get_foreign_keys implementations in
tabularis/src-tauri/src/drivers/postgres/mod.rs (as updated by #939)
are the reference. The parity suite's golden files
(get_columns_all_types.json, get_foreign_keys_orders.json, etc.) are
updated by #939 to include the new fields — the plugin's parity tests
will need to match.
Tests
- Unit tests for
row_to_table_columnextractingnumeric_precision/
numeric_scale(can be tested without a live DB — the function takes
a&tokio_postgres::Row). - Unit tests for
row_to_foreign_keyextractingseq_in_fk. - Live/parity tests confirming the golden files match with the new
fields.
Scope
Three functions to update (get_columns, get_foreign_keys,
get_all_columns_batch / get_all_foreign_keys_batch / get_view_columns
share the same query/row-mapping code). All changes are additive — no
existing field changes, no breaking behavior.
Reference: Tabularis PR #939
Activity
feat: add numeric_precision/scale and seq_in_fk for DDL type fidelity (…