Skip to content

Instantly share code, notes, and snippets.

@sshkarupa
Forked from sualeh/README.md
Created April 18, 2024 14:44
Show Gist options
  • Save sshkarupa/af0de57eebe2329b2e4eb286fdb851e0 to your computer and use it in GitHub Desktop.
Save sshkarupa/af0de57eebe2329b2e4eb286fdb851e0 to your computer and use it in GitHub Desktop.

Revisions

  1. @sualeh sualeh revised this gist Jan 25, 2023. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -65,4 +65,3 @@ entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>
    Here is an [example file](https://gist.github.com/sualeh/ea272410356527d3132809061e8ba5b4#file-schema-puml) with everything put together. You can visualize diagram this online using [PlantText](https://www.planttext.com/) editor, and then create your own.

    Take a look at [SchemaCrawler](https://www.schemacrawler.com/), which extends functionality by [connecting to your database server and generating a PlantUML schema diagram from it using this technique](https://dev.to/sualeh/generate-good-looking-plantuml-diagrams-for-your-database-3g19).

  2. @sualeh sualeh revised this gist Jan 22, 2023. No changes.
  3. @sualeh sualeh revised this gist Jan 22, 2023. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@

    Here is an example of a PlantUML schema diagram, and we will build up the code to generate it.

    ![Schema diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wxlre7honzzrk3zxpa3.jpg)

    To start, describe your schemas, tables and columns using this syntax as an example.

    ```
    @@ -29,7 +31,7 @@ Then, using those ids, you can define foreign key relationships like this:
    id_208b5502.id_f521e766::ID ||--o{ id_208b5502.id_ead84c5d::AUTHORID : FK_AUTHOR
    ```

    The secret sauce to this meta-language in the file header, and it looks like this:
    The secret sauce to this meta-language is in the file header, and it looks like this:

    ```
    !theme plain
    @@ -62,5 +64,5 @@ entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>

    Here is an [example file](https://gist.github.com/sualeh/ea272410356527d3132809061e8ba5b4#file-schema-puml) with everything put together. You can visualize diagram this online using [PlantText](https://www.planttext.com/) editor, and then create your own.

    Take a look at [SchemaCrawler](https://www.schemacrawler.com/diagramming.html), which extends functionality by connecting to your database server and generating a PlantUML schema diagram from it using this technique.
    Take a look at [SchemaCrawler](https://www.schemacrawler.com/), which extends functionality by [connecting to your database server and generating a PlantUML schema diagram from it using this technique](https://dev.to/sualeh/generate-good-looking-plantuml-diagrams-for-your-database-3g19).

  4. @sualeh sualeh revised this gist Jan 22, 2023. No changes.
  5. @sualeh sualeh revised this gist Jan 22, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    # Create a Nice-looking Schema Diagrams in PlantUML
    # Create Nice-looking Schema Diagrams in PlantUML

    [PlantUML](https://plantuml.com/) is a descriptive language to generate a number of types of software diagrams, such as sequence, class, deployment and state diagrams, and many others. PlantUML does not generate very good looking schema diagrams out of the box, but it supports themes and preprocessed macros. If you use themes and macros, you can not only use a simpified syntax, but also generate beautiful diagrams.
    [PlantUML](https://plantuml.com/) is a descriptive language to generate a number of types of software diagrams, such as sequence, class, deployment and state diagrams, and many others. PlantUML does not generate very good-looking schema diagrams out of the box, but it supports themes and preprocessed macros. If you use themes and macros, you can not only use a simplified syntax, but also generate beautiful diagrams.

    Here is an example of a PlantUML shcema diagram, and we will build up the code to generate it.
    Here is an example of a PlantUML schema diagram, and we will build up the code to generate it.

    To start, describe your schemas, tables and columns using this syntax as an example.
    To start, describe your schemas, tables and columns using this syntax as an example.

    ```
    $schema("PUBLISHER_SALES", "id_7f7f6c20") {
  6. @sualeh sualeh revised this gist Jan 22, 2023. 1 changed file with 0 additions and 0 deletions.
    Binary file added schema.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  7. @sualeh sualeh revised this gist Jan 22, 2023. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -59,3 +59,8 @@ entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>
    {field} <color:#White><&media-record></color> $name
    !endprocedure
    ```

    Here is an [example file](https://gist.github.com/sualeh/ea272410356527d3132809061e8ba5b4#file-schema-puml) with everything put together. You can visualize diagram this online using [PlantText](https://www.planttext.com/) editor, and then create your own.

    Take a look at [SchemaCrawler](https://www.schemacrawler.com/diagramming.html), which extends functionality by connecting to your database server and generating a PlantUML schema diagram from it using this technique.

  8. @sualeh sualeh created this gist Jan 22, 2023.
    61 changes: 61 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    # Create a Nice-looking Schema Diagrams in PlantUML

    [PlantUML](https://plantuml.com/) is a descriptive language to generate a number of types of software diagrams, such as sequence, class, deployment and state diagrams, and many others. PlantUML does not generate very good looking schema diagrams out of the box, but it supports themes and preprocessed macros. If you use themes and macros, you can not only use a simpified syntax, but also generate beautiful diagrams.

    Here is an example of a PlantUML shcema diagram, and we will build up the code to generate it.

    To start, describe your schemas, tables and columns using this syntax as an example.

    ```
    $schema("PUBLISHER_SALES", "id_7f7f6c20") {
    $table("SALES", "id_751e68cc") {
    $column("POSTALCODE"): VARCHAR NOT NULL
    $column("COUNTRY"): VARCHAR NOT NULL
    $fk("BOOKID"): INTEGER
    $fk("COUPON_ID"): INTEGER
    $column("PERIODENDDATE"): DATE
    $column("TOTALAMOUNT"): DOUBLE
    }
    }
    ```

    You can pick any id, as long as it is unique across the diagram. This will allow you to have tables with the same name in different schemas.

    Then, using those ids, you can define foreign key relationships like this:

    ```
    id_208b5502.id_f521e766::ID ||--o{ id_208b5502.id_ead84c5d::AUTHORID : FK_AUTHOR
    ```

    The secret sauce to this meta-language in the file header, and it looks like this:

    ```
    !theme plain
    hide empty methods
    !procedure $schema($name, $slug)
    package "$name" as $slug <<Rectangle>>
    !endprocedure
    !procedure $table($name, $slug)
    entity "<b>$name</b>" as $slug << (T, Orange) table >>
    !endprocedure
    !procedure $view($name, $slug)
    entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>
    !endprocedure
    !procedure $pk($name)
    <color:#GoldenRod><&key></color> <b>$name</b>
    !endprocedure
    !procedure $fk($name)
    <color:#Silver><&key></color> $name
    !endprocedure
    !procedure $column($name)
    {field} <color:#White><&media-record></color> $name
    !endprocedure
    ```
    84 changes: 84 additions & 0 deletions schema.puml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    @startuml

    !theme plain
    hide empty methods

    !procedure $schema($name, $slug)
    package "$name" as $slug <<Rectangle>>
    !endprocedure

    !procedure $table($name, $slug)
    entity "<b>$name</b>" as $slug << (T, Orange) table >>
    !endprocedure

    !procedure $view($name, $slug)
    entity "<b>$name</b>" as $slug << (V, Aquamarine) view >>
    !endprocedure

    !procedure $pk($name)
    <color:#GoldenRod><&key></color> <b>$name</b>
    !endprocedure

    !procedure $fk($name)
    <color:#Silver><&key></color> $name
    !endprocedure

    !procedure $column($name)
    {field} <color:#White><&media-record></color> $name
    !endprocedure


    title "Publications Schema"


    $schema("PUBLICATIONS", "id_208b5502") {

    $table("AUTHORS", "id_f521e766") {
    $pk("ID"): INTEGER NOT NULL
    $column("FIRSTNAME"): VARCHAR NOT NULL
    $column("LASTNAME"): VARCHAR NOT NULL
    $column("ADDRESS1"): VARCHAR
    $column("ADDRESS2"): VARCHAR
    $column("CITY"): VARCHAR
    $column("STATE"): CHARACTER
    $column("POSTALCODE"): VARCHAR
    $column("COUNTRY"): VARCHAR
    }

    $table("BOOKS", "id_f4a675c8") {
    $pk("ID"): INTEGER NOT NULL
    $column("TITLE"): VARCHAR NOT NULL
    $column("DESCRIPTION"): VARCHAR
    $column("PUBLISHERID"): INTEGER NOT NULL
    $column("PUBLICATIONDATE"): DATE
    $column("PRICE"): DOUBLE
    }

    $table("BOOKAUTHORS", "id_ead84c5d") {
    $fk("BOOKID"): INTEGER NOT NULL
    $fk("AUTHORID"): INTEGER NOT NULL
    $column("SOMEDATA"): VARCHAR
    }

    }


    $schema("PUBLISHER_SALES", "id_7f7f6c20") {

    $table("SALES", "id_751e68cc") {
    $column("POSTALCODE"): VARCHAR NOT NULL
    $column("COUNTRY"): VARCHAR NOT NULL
    $fk("BOOKID"): INTEGER
    $fk("COUPON_ID"): INTEGER
    $column("PERIODENDDATE"): DATE
    $column("TOTALAMOUNT"): DOUBLE
    }

    }


    id_208b5502.id_f521e766::ID ||--o{ id_208b5502.id_ead84c5d::AUTHORID : FK_AUTHOR
    id_208b5502.id_f4a675c8::ID ||--o{ id_7f7f6c20.id_751e68cc::BOOKID : FK_SALES_BOOK
    id_208b5502.id_f4a675c8::ID ||--o{ id_208b5502.id_ead84c5d::BOOKID : FK_BOOK

    @enduml