mirror of
https://github.com/safishamsi/graphify.git
synced 2026-07-12 18:37:12 +00:00
5d0392524a
The SQL parser (`extract_sql`) previously only extracted foreign key relationships defined inline within CREATE TABLE column definitions. FK constraints added via ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... REFERENCES were silently ignored. Additionally, `_obj_name()` only read the first identifier child of object_reference nodes, so schema-qualified names like `Sales.Customer` were truncated to just `Sales`. Changes: - Add `alter_table` handler to `walk()` that extracts FK edges from ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ... REFERENCES - Fix `_obj_name()` to read the full object_reference text, preserving schema-qualified names (e.g. `Sales.Customer`) - Fix inline FK resolution in create_table and _walk_from_refs to use full object_reference text instead of first identifier only
12 lines
325 B
SQL
12 lines
325 B
SQL
CREATE TABLE Sales.Customer (
|
|
CustomerID SERIAL PRIMARY KEY,
|
|
Name TEXT NOT NULL
|
|
);
|
|
|
|
CREATE TABLE Sales.SalesOrder (
|
|
OrderID SERIAL PRIMARY KEY,
|
|
CustomerID INT REFERENCES Sales.Customer(CustomerID)
|
|
);
|
|
|
|
ALTER TABLE Sales.SalesOrder ADD CONSTRAINT fk_cust FOREIGN KEY (CustomerID) REFERENCES Sales.Customer(CustomerID);
|