Skip to content

AWK script to create a ER diagram for SAP Cloud Application Programming Model

License

Notifications You must be signed in to change notification settings

rabestro/sap-cds-erd

Repository files navigation

SAP CDS Entity Relationship Diagrams

The small AWK script generate mermaid Entity Relationship diagrams from SAP Cloud Application Programming Model files.

How to run script

gawk -f src/cds2erd.awk db/* > bookstore.mermaid

Alternatively, you can move the script to the bin directory and make it executable:

chmod +x cds2erd.awk

In this case you can call the script without specifying an interpreter:

cds2erd.awk schema.cds > schema.mermaid

Sample generated ER diagram

Below is the database schema from the project SAP Cloud CAP Samples Bookstore

erDiagram
    Books {
        String title
        String descr
        Integer stock
        Decimal price
        Currency currency
        Decimal rating
        TechnicalBooleanFlag isReviewable
    }

    Authors {
        String name
        Date dateOfBirth
        Date dateOfDeath
        String placeOfBirth
        String placeOfDeath
    }

    Genres {
        String name
        String descr
        Integer ID PK
    }

    Notes {
        String note
    }

    Orders {
        String OrderNo
        User buyer
        Decimal total
        Currency currency
    }

    OrderItems {
        Integer quantity
        Decimal amount
    }

    Reviews {
        Rating rating
        String title
        String text
    }

    Orders |o--o{ OrderItems : ""
    OrderItems |o--o| Books : ""
    Genres }o--o| Genres : ""
    Books |o--o{ Reviews : ""
    Books |o--o| Genres : ""
    Books }o--o| Authors : ""
Loading