oracle / quicksql

A library for generating DDL SQL and entity-relationship-diagrams from Quick SQL code
Universal Permissive License v1.0
52 stars 11 forks source link

Please Support /setnull Option Wherever /cascade is Supported to Enable Reverse Engineering Existing Schemas to Quick SQL #52

Closed stevemuench closed 6 months ago

stevemuench commented 7 months ago

In order to reverse-engineer existing schemas into QuickSQL for visualization in the Oracle APEX QuickSQL diagram, support for the ON DELETE SET NULL foreign key constraint variant is required to round out support for the different kinds of foreign key constraints that can be expressed. Ideally, wherever /cascade is supported today, QuickSQL would also recognize /setnull and generate the appropriate ON DELETE SET NULL for the SQL in the foreign key constraint DDL it produces.

vadim-tropashko commented 7 months ago

To doublecheck:

departments
    dname
    emp  /setnull
        department_id /fk departments 
        ename

should output

...
create table emp (
    id                             number generated by default on null as identity 
                                   constraint emp_id_pk primary key,
    department_id                  number
                                   constraint emp_department_id_fk
                                   references departments on delete set null,
    ename                          varchar2(255 char)
)
;
...

Then

team_members
   username
projects /insert 2
   name
   project_lead /nn /references team_members /setnull

would raise an error due to conflicting directives.

stevemuench commented 7 months ago

I didn't understand why the team_members and project example would not simply result in a foreign key project_lead that would be set null if the team member to which it referred was deleted. Can you clarify what you mean by conflicting directives? It would definitely be an error to list both /cascade and /setnull together, but I thought /references was a synonym for /fk and that the lack of having either /setnull or /cascade was what represented the default ON DELETE RESTRICT behavior (which is omitted from the DDL since it's the behavior of a foreign key by default).

vadim-tropashko commented 7 months ago

The /nn directive is conflicting with /setnull. (This is a test example for /cascade that is converted to /setnull, and /nn is just an artifact).

stevemuench commented 7 months ago

Thanks for clarifying. I missed the /nn in there.

vadim-tropashko commented 6 months ago

in 1.2.6