Commit ba0bf98
committed
core: DDL builders + IndexInfo / ForeignKeyInfo (DDL UI #1)
Lay the core SQL-generation foundation for the upcoming Structure
workspace tab:
- crates/core/src/query.rs: IndexInfo + ForeignKeyInfo structs
carrying secondary-index and FK metadata (with primary flag on
the implicit PK index so the UI can render it as read-only).
- crates/core/src/connection.rs: extend the Connection trait with
fetch_indexes() and fetch_foreign_keys() default impls returning
empty Vec, so existing drivers compile before they're filled in.
- crates/core/src/read_only.rs: forward the two new reads to the
inner connection (read-only blocks mutations, not introspection).
- crates/core/src/sql_ddl.rs: the full CREATE / DROP / ALTER DDL
surface across MySQL + Postgres + SQLite — build_create_table,
build_drop_table, build_rename_table, build_add_column,
build_drop_column, build_rename_column, build_alter_column,
build_reorder_column (MySQL only), build_create_index,
build_drop_index, build_add_foreign_key, build_drop_foreign_key.
Dialect quirks captured:
- Postgres auto-increment renders as SERIAL / BIGSERIAL / SMALLSERIAL
based on the user-typed integer width.
- MySQL ALTER COLUMN routes through MODIFY COLUMN which replaces the
whole definition (single-call); Postgres emits per-attribute
ALTER COLUMN ... TYPE / SET NOT NULL / SET DEFAULT.
- SQLite limits surface as BuildDdlError::SqliteNotSupported for
alter-type / alter-nullable / alter-default / drop-FK so the UI
can disable the affordances rather than fall through to a runtime
driver error.
- SQLite FK constraints get a leading PRAGMA foreign_keys = ON
emitted by build_create_table when the columns list contains FKs.
43 unit tests cover every builder × every driver × edge cases
(composite PK, schema qualification, identifier quote-doubling,
empty-name validation, default expressions, auto-increment routing).1 parent 1b4094c commit ba0bf98
5 files changed
Lines changed: 1166 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
52 | 68 | | |
53 | 69 | | |
54 | 70 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
12 | 41 | | |
13 | 42 | | |
14 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
| |||
0 commit comments