Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Last active March 5, 2025 23:27
Show Gist options
  • Save dannguyen/f056d05bb7fec408bb7c14ea1552c349 to your computer and use it in GitHub Desktop.
Save dannguyen/f056d05bb7fec408bb7c14ea1552c349 to your computer and use it in GitHub Desktop.

Revisions

  1. dannguyen revised this gist Jul 17, 2019. 1 changed file with 13 additions and 4 deletions.
    17 changes: 13 additions & 4 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -135,13 +135,13 @@ The output of that Bash command will be a file `/tmp/tmpdb.sqlite`, which looks



    ## graphviz properties
    ## GraphViz visual properties

    You can edit `config/schemacrawler.config.properties`:
    You can edit `schemacrawler.config.properties`, which is found wherever you installed the schemacrawler distribution – e.g. if you ran my installer script, it would be in `/usr/local/opt/schemacrawler/config/schemacrawler.config.properties`

    ```
    88667/how-to-influence-layout-of-graph-items
    Some example settings:

    ```
    schemacrawler.format.no_schemacrawler_info=true
    schemacrawler.format.show_database_info=true
    schemacrawler.format.show_row_counts=true
    @@ -163,4 +163,13 @@ schemacrawler.graph.graphviz.edge.fontname=Consolas
    schemacrawler.graph.graphviz.edge.arrowsize=1.5
    ```

    If you append the previous snippet to the default `schemacrawler.config.properties`, you'll get output that looks like this:

    ![image](https://user-images.githubusercontent.com/121520/61417204-f00ef500-a8e5-11e9-9e97-e690b23e31aa.png)



    More info about GraphViz in this StackOverflow Q:

    [How to influence layout of graph items?](https://stackoverflow.com/questions/11588667/how-to-influence-layout-of-graph-items)

  2. dannguyen revised this gist Jul 17, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,7 @@ Now that `schemacrawler` is installed as an executable shell command, here's an
    ```


    ### Bootload a database
    ### Bootload a sample SQLite database and test out schemacrawler

    Just in case you don't have a database to play around with, you can copy paste this sequence of SQLite commands into your **Bash** shell, which will create the following empty database file at `/tmp/tmpdb.sqlite`

    @@ -129,6 +129,10 @@ schemacrawler -server sqlite \
    -outputfile /tmp/mytmpdb.png
    ```

    The output of that Bash command will be a file `/tmp/tmpdb.sqlite`, which looks like this:

    ![/tmp/tmpdb.sqlite](https://user-images.githubusercontent.com/121520/61403484-ede86e80-a8c4-11e9-8bda-f9ceb63b6101.png)



    ## graphviz properties
  3. dannguyen revised this gist Jul 17, 2019. 3 changed files with 25 additions and 7 deletions.
    23 changes: 19 additions & 4 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # Generating cool SQLite database diagrams with schemacrawler on Mac OS
    # Installing and using schemacrawler for MacOS

    *This was tested on MacOS 10.13*
    ## A recipe for generating cool SQLite database diagrams with schemacrawler on MacOS

    *This was tested on MacOS 10.14.5 on 2019-07-16*

    [schemacrawler is a free and open-source database schema discovery and comprehension tool](http://www.schemacrawler.com/). It can be invoked from the command-line to produce, using [GraphViz](http://www.graphviz.org/), images/pdfs from a SQLite (or other database type) file.
    It can be used from the command-line to generate schema diagrams like these:
    @@ -45,11 +47,23 @@ You can copy the script into a file and invoke it, or copy-paste it directly int

    (An older version of this script can be found [here](#file-OLDscript-schemacrawler-on-macos-sh))

    > Note: The attached script [script-schemacrawler-on-macos.sh](#file-script-schemacrawler-on-macos-sh) has a few defaults – e.g. `/usr/local/opt/` and `/usr/local/bin/` – which are assumed to be writeable, but you can change those default vars for yourself.
    #### A couple of notes about

    The script [script-schemacrawler-on-macos.sh](#file-script-schemacrawler-on-macos-sh) has a few defaults – e.g. `/usr/local/opt/` and `/usr/local/bin/` – which are assumed to be writeable, but you can change those default vars for yourself.

    One of the effects of is that it creates a Bash script named something like

    Its contents are:


    This script is a derivation of schemacrawler's [schemacrawler-distrib/src/assembly/schemacrawler.sh](https://github.com/schemacrawler/SchemaCrawler/blob/a3fea8be74ae28d6e8318c14f2c3f4be314efe2a/schemacrawler-distrib/src/assembly/schemacrawler.sh), the contents of which are:



    ## General usage

    Now that `schemacrawler` is installed as an executable shell command, here's an example of how to invoke it – change `DBNAME.sqlite` and `OUTPUT_IMAGE_FILE.png` to something appropriate for your usecase:

    ```sh
    schemacrawler -server sqlite \
    -database DBNAME.sqlite \
    @@ -63,7 +77,7 @@ You can copy the script into a file and invoke it, or copy-paste it directly int

    ### Bootload a database

    Just in case you don't have a database to playround with
    Just in case you don't have a database to play around with, you can copy paste this sequence of SQLite commands into your **Bash** shell, which will create the following empty database file at `/tmp/tmpdb.sqlite`

    ```sh
    echo '''
    @@ -103,6 +117,7 @@ CREATE TABLE violation (
    | sqlite3 /tmp/tmpdb.sqlite
    ```

    Invoke `schemacrawler` like so:

    ```
    schemacrawler -server sqlite \
    8 changes: 5 additions & 3 deletions script-schemacrawler-on-macos.sh
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ _SCH_SCRIPT_NAME="${_INSTALL_DIR}/schemacrawler-macos-opt.sh"

    # Download and unzip into $_TEMPDIR
    mkdir -p ${_TEMPDIR}
    printf "\nDownloading ${_SCH_URL} \n\tinto ${_TEMPDIR}\n\n"
    printf "\nDownloading\n\t ${_SCH_URL} \n\tinto temporary directory: ${_TEMPDIR}\n\n"
    curl -Lo ${_SCH_ZNAME} ${_SCH_URL}
    unzip ${_SCH_ZNAME} -d ${_TEMPDIR}
    printf "\n\n"
    @@ -55,10 +55,12 @@ cp -r /tmp/${_SCH_FNAME}/_schemacrawler/ ${_INSTALL_DIR}
    # https://stackoverflow.com/questions/2953081/how-can-i-write-a-heredoc-to-a-file-in-bash-script
    printf "\n\nCreating ${_SCH_SCRIPT_NAME}"

    # The shell code below is a variation of what's found at:
    # https://github.com/schemacrawler/SchemaCrawler/blob/a3fea8be74ae28d6e8318c14f2c3f4be314efe2a/schemacrawler-distrib/src/assembly/schemacrawler.sh
    cat << SCSCRIPT > ${_SCH_SCRIPT_NAME}
    #!/usr/bin/env bash
    SCHEMA_CRAWL_DIR=${_INSTALL_DIR}
    java -cp \$(echo \${SCHEMA_CRAWL_DIR}/lib/*.jar | tr ' ' ':'):\${SCHEMA_CRAWL_DIR}/config schemacrawler.Main "\$@"
    SCHEMACRAWL_DIR=${_INSTALL_DIR}
    java -cp \$(echo \${SCHEMACRAWL_DIR}/lib/*.jar | tr ' ' ':'):\${SCHEMACRAWL_DIR}/config schemacrawler.Main "\$@"
    SCSCRIPT

    # make the shell script executable and symlink it
    1 change: 1 addition & 0 deletions script_OLD-schemacrawler-on-macos.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # This was tested on MacOS 10.13

    # set up some variables to reduce redundancy

  4. dannguyen revised this gist Jul 17, 2019. 2 changed files with 15 additions and 40 deletions.
    49 changes: 11 additions & 38 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -24,55 +24,28 @@ brew install graphviz
    This section gives an example of how to install `schemacrawler` so that you can invoke it with your shell. There isn't a Homebrew recipe, so the shell commands basically:

    - Download a release zip from [schemacrawler/releases](https://github.com/schemacrawler/SchemaCrawler/releases)
    - Copies the relevant subdir from the release into `/usr/local/opt/schemacrawler`
    - Copies the relevant subdir from the release into a local directory, e.g. `/usr/local/opt/schemacrawler`
    - Creates a simple shell script that saves you from having to run `schemacrawler` via the `java` executable
    - symlinks this shell script into `/usr/local/bin`
    - symlinks this shell script into an executable path, e.g. `/usr/local/bin`

    The rest of these instructions assume you have these directories created (which you probably do if you are using **Homebrew**, and that you have write access to them:

    ```
    /usr/local/opt
    /usr/local/bin
    ```

    Additionally, I assume that `/usr/loca/bin` is part of `$PATH`, which, again, it probably is if you are using **Homebrew**

    ### Download and install schemacrawler
    ## Downloading and installing schemacrawler

    The latest releases can be found on the Github page:

    https://github.com/schemacrawler/SchemaCrawler/releases/

    ```sh
    # set up some variables to reduce redundancy

    _SCH_VERSION='14.21.02'
    _SCH_BNAME="schemacrawler-${_SCH_VERSION}-distribution"
    _SCH_TNAME="/tmp/${SCH_BNAME}.zip"
    _SCH_URL="https://github.com/schemacrawler/SchemaCrawler/releases/download/v${_SCH_VERSION}/${_SCH_BNAME}.zip"
    _SCH_DIR='/usr/local/opt/schemacrawler'
    _SCH_SH="${_SCH_DIR}/schemacrawler-macos-opt.sh"

    # Download and unzip into /tmp
    curl -Lo ${_SCH_TNAME} ${_SCH_URL}
    unzip ${_SCH_TNAME}

    # Move subdir from release package into /usr/local/opt
    mkdir -p ${_SCH_DIR}
    cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ ${_SCH_DIR}
    ### Setting up schemacrawler to run on your system via `$ schemacrawler`

    # create the shell script manually
    echo '#!/usr/bin/env bash' > ${_SCH_SH}
    echo "SC_DIR=${_SCH_DIR}" >> ${_SCH_SH}
    echo "java -cp \$(echo \$SC_DIR/lib/*.jar | tr ' ' ':'):\$SC_DIR/config schemacrawler.Main \"\$@\"" \
    >> ${_SCH_SH}
    In this gist, I've attached a shell script [script-schemacrawler-on-macos.sh](#file-script-schemacrawler-on-macos-sh) that automates the downloading of the schemacrawler ZIP file from its Github repo, installs it, creates a helper script, and creates a symlink to that helper script so you can invoke it via:

    # make it executable and symlink it

    chmod +x ${_SCH_SH}
    ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler
    ```sh
    $ schemacrawler ...
    ```
    You can copy the script into a file and invoke it, or copy-paste it directly into Bash. Obviously, as with anything you copy-paste, read it for yourself to make sure I'm not attempting to do something malicious.

    (An older version of this script can be found [here](#file-OLDscript-schemacrawler-on-macos-sh))

    > Note: The attached script [script-schemacrawler-on-macos.sh](#file-script-schemacrawler-on-macos-sh) has a few defaults – e.g. `/usr/local/opt/` and `/usr/local/bin/` – which are assumed to be writeable, but you can change those default vars for yourself.

    ## General usage
    6 changes: 4 additions & 2 deletions script-schemacrawler-on-macos.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/sh

    ## Tested on MacOS 10.14.5
    ## Gist URL: https://gist.github.com/dannguyen/f056d05bb7fec408bb7c14ea1552c349

    ########################
    # Variables and defaults
    @@ -15,9 +15,11 @@ _SCH_VERSION='15.06.01'
    _TEMPDIR=/tmp

    # Pick the path to store the app and the shell script
    # NOTE: The parent dir – e.g. /usr/local/opt – must be writable
    _INSTALL_DIR=/usr/local/opt/schemacrawler

    # Pick the symlink for the path; ideally, it's a path that is in your system PATH
    # Pick the symlink for the path; ideally, it's a path that is in your system's executable PATH
    # NOTE: The executable PATH – e.g. /usr/local/bin – must be writable
    _SCH_SYMLINK=/usr/local/bin/schemacrawler


  5. dannguyen revised this gist Jul 17, 2019. 2 changed files with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions script_OLD-schemacrawler-on-macos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@

    # set up some variables to reduce redundancy

    _SCH_VERSION='14.21.02'
    _SCH_BNAME="schemacrawler-${_SCH_VERSION}-distribution"
    _SCH_TNAME="/tmp/${SCH_BNAME}.zip"
    _SCH_URL="https://github.com/schemacrawler/SchemaCrawler/releases/download/v${_SCH_VERSION}/${_SCH_BNAME}.zip"
    _SCH_DIR='/usr/local/opt/schemacrawler'
    _SCH_SH="${_SCH_DIR}/schemacrawler-macos-opt.sh"

    # Download and unzip into /tmp
    curl -Lo ${_SCH_TNAME} ${_SCH_URL}
    unzip ${_SCH_TNAME}

    # Move subdir from release package into /usr/local/opt
    mkdir -p ${_SCH_DIR}
    cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ ${_SCH_DIR}

    # create the shell script manually
    echo '#!/usr/bin/env bash' > ${_SCH_SH}
    echo "SC_DIR=${_SCH_DIR}" >> ${_SCH_SH}
    echo "java -cp \$(echo \$SC_DIR/lib/*.jar | tr ' ' ':'):\$SC_DIR/config schemacrawler.Main \"\$@\"" \
    >> ${_SCH_SH}

    # make it executable and symlink it

    chmod +x ${_SCH_SH}
    ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler
  6. dannguyen revised this gist Jul 17, 2019. 1 changed file with 65 additions and 0 deletions.
    65 changes: 65 additions & 0 deletions install-schemacrawler-on-macos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    #!/bin/sh

    ## Tested on MacOS 10.14.5

    ########################
    # Variables and defaults
    ########################

    # Modify this for whatever version you're trying to download
    _SCH_VERSION='15.06.01'

    # Pick your own temp dir
    # Note that the zip archive by default creates and unzips into a subdir,
    # e.g. `schemacrawler-15.06.01-distribution`
    _TEMPDIR=/tmp

    # Pick the path to store the app and the shell script
    _INSTALL_DIR=/usr/local/opt/schemacrawler

    # Pick the symlink for the path; ideally, it's a path that is in your system PATH
    _SCH_SYMLINK=/usr/local/bin/schemacrawler


    #####
    # These defaults are derived from above

    # The filename stem for the downloadable zip, as it exists on the Github filesystem,
    # and the subdir it creates when unzipped
    _SCH_FNAME="schemacrawler-${_SCH_VERSION}-distribution"
    _SCH_URL="https://github.com/schemacrawler/SchemaCrawler/releases/download/v${_SCH_VERSION}/${_SCH_FNAME}.zip"
    _SCH_ZNAME="${_TEMPDIR}/${_SCH_FNAME}.zip"
    # `schema-macos-opt.sh` is just the arbitrary name from which the symlink will be based
    _SCH_SCRIPT_NAME="${_INSTALL_DIR}/schemacrawler-macos-opt.sh"


    #########
    # Actions
    #########

    # Download and unzip into $_TEMPDIR
    mkdir -p ${_TEMPDIR}
    printf "\nDownloading ${_SCH_URL} \n\tinto ${_TEMPDIR}\n\n"
    curl -Lo ${_SCH_ZNAME} ${_SCH_URL}
    unzip ${_SCH_ZNAME} -d ${_TEMPDIR}
    printf "\n\n"

    # Move subdir from release package into /usr/local/opt
    printf "\nMoving contents of /tmp/${_SCH_FNAME}/_schemacrawler/ \n\tinto ${_INSTALL_DIR}"
    mkdir -p ${_INSTALL_DIR}
    cp -r /tmp/${_SCH_FNAME}/_schemacrawler/ ${_INSTALL_DIR}

    # create the shell script manually
    # https://stackoverflow.com/questions/2953081/how-can-i-write-a-heredoc-to-a-file-in-bash-script
    printf "\n\nCreating ${_SCH_SCRIPT_NAME}"

    cat << SCSCRIPT > ${_SCH_SCRIPT_NAME}
    #!/usr/bin/env bash
    SCHEMA_CRAWL_DIR=${_INSTALL_DIR}
    java -cp \$(echo \${SCHEMA_CRAWL_DIR}/lib/*.jar | tr ' ' ':'):\${SCHEMA_CRAWL_DIR}/config schemacrawler.Main "\$@"
    SCSCRIPT

    # make the shell script executable and symlink it
    printf "\n\nSymlinking ${_SCH_SCRIPT_NAME} \n\tto ${_SCH_SYMLINK}\n\n"
    chmod +x ${_SCH_SCRIPT_NAME}
    ln -sf ${_SCH_SCRIPT_NAME} ${_SCH_SYMLINK}
  7. dannguyen revised this gist Jun 15, 2018. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -143,6 +143,32 @@ schemacrawler -server sqlite \



    ## graphviz properties

    You can edit `config/schemacrawler.config.properties`:

    ```
    88667/how-to-influence-layout-of-graph-items
    schemacrawler.format.no_schemacrawler_info=true
    schemacrawler.format.show_database_info=true
    schemacrawler.format.show_row_counts=true
    schemacrawler.format.identifier_quoting_strategy=quote_if_special_characters
    schemacrawler.graph.graphviz.nodes.ranksep=circo
    schemacrawler.graph.graphviz.graph.layout=circo
    schemacrawler.graph.graphviz.graph.splines=ortho
    schemacrawler.graph.graphviz.node.shape=folder
    schemacrawler.graph.graphviz.node.style=rounded,filled
    schemacrawler.graph.graphviz.node.fillcolor=#fcfdfc
    #schemacrawler.graph.graphviz.node.color=red
    schemacrawler.graph.graphviz.graph.fontname=Helvetica Neue
    schemacrawler.graph.graphviz.node.fontname=Consolas
    schemacrawler.graph.graphviz.edge.fontname=Consolas
    schemacrawler.graph.graphviz.edge.arrowsize=1.5
    ```


  8. dannguyen revised this gist Jun 15, 2018. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,15 @@

    *This was tested on MacOS 10.13*

    [schemacrawler is a free and open-source database schema discovery and comprehension tool](http://www.schemacrawler.com/).

    [schemacrawler is a free and open-source database schema discovery and comprehension tool](http://www.schemacrawler.com/). It can be invoked from the command-line to produce, using [GraphViz](http://www.graphviz.org/), images/pdfs from a SQLite (or other database type) file.
    It can be used from the command-line to generate schema diagrams like these:

    ![image](https://user-images.githubusercontent.com/121520/41448959-de545a74-7012-11e8-99f9-520d76a683b8.png)


    To see more examples of commands and diagrams, visit scheacrawler's docs: http://www.schemacrawler.com/diagramming.html


    ## Install graphviz dependency

    For schema drawing, `schemacrawler` uses graphviz, which can be installed via the [Homebrew](https://brew.sh/) package manager:
  9. dannguyen revised this gist Jun 15, 2018. 1 changed file with 29 additions and 11 deletions.
    40 changes: 29 additions & 11 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -9,48 +9,66 @@ It can be used from the command-line to generate schema diagrams like these:
    ![image](https://user-images.githubusercontent.com/121520/41448959-de545a74-7012-11e8-99f9-520d76a683b8.png)



    ## Install graphviz dependency

    For schema drawing, `schemacrawler` uses graphviz, which can be installed via homebrew:
    For schema drawing, `schemacrawler` uses graphviz, which can be installed via the [Homebrew](https://brew.sh/) package manager:

    ```sh
    brew install graphviz
    ```

    ## Install schemacrawler
    ## Installing `schemacrawler` as a command-line tool

    This section gives an example of how to install `schemacrawler` so that you can invoke it with your shell. There isn't a Homebrew recipe, so the shell commands basically:

    - Download a release zip from [schemacrawler/releases](https://github.com/schemacrawler/SchemaCrawler/releases)
    - Copies the relevant subdir from the release into `/usr/local/opt/schemacrawler`
    - Creates a simple shell script that saves you from having to run `schemacrawler` via the `java` executable
    - symlinks this shell script into `/usr/local/bin`

    The rest of these instructions assume you have these directories created (which you probably do if you are using **Homebrew**, and that you have write access to them:

    ```
    /usr/local/opt
    /usr/local/bin
    ```

    Additionally, I assume that `/usr/loca/bin` is part of `$PATH`, which, again, it probably is if you are using **Homebrew**

    ### Download and install schemacrawler

    The latest releases can be found on the Github page:

    https://github.com/schemacrawler/SchemaCrawler/releases/

    ```sh
    # set up some variables to reduce redundancy

    _SCH_VERSION='14.21.02'
    _SCH_BNAME="schemacrawler-${_SCH_VERSION}-distribution"
    _SCH_TNAME="/tmp/${SCH_BNAME}.zip"
    _SCH_URL="https://github.com/schemacrawler/SchemaCrawler/releases/download/v${_SCH_VERSION}/${_SCH_BNAME}.zip"
    _SCH_DIR='/usr/local/opt/schemacrawler'
    _SCH_SH="${_SCH_DIR}/schemacrawler-macos-opt.sh"

    # Download and unzip into /tmp
    curl -Lo ${_SCH_TNAME} ${_SCH_URL}

    unzip ${_SCH_TNAME}

    # Move subdir from release package into /usr/local/opt
    mkdir -p ${_SCH_DIR}
    cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ /usr/local/opt/schemacrawler/
    cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ ${_SCH_DIR}

    # create the shell script
    # create the shell script manually
    echo '#!/usr/bin/env bash' > ${_SCH_SH}
    echo "SC_DIR=${_SCH_DIR}" >> ${_SCH_SH}
    echo "java -cp \$(echo \$SC_DIR/lib/*.jar | tr ' ' ':'):\$SC_DIR/config schemacrawler.Main \"\$@\"" \
    >> ${_SCH_SH}

    # make it executable
    chmod +x ${_SCH_SH}
    # make it executable and symlink it

    # symlink it
    ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler

    chmod +x ${_SCH_SH}
    ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler
    ```


  10. dannguyen revised this gist Jun 15, 2018. 1 changed file with 0 additions and 8 deletions.
    8 changes: 0 additions & 8 deletions schemacrawler-macos-opt.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    #!/usr/bin/env bash
    # A shell script customized for modern MacOS, which assumes /usr/local/bin and /usr/local/opt exist
    # https://gist.github.com/dannguyen/f056d05bb7fec408bb7c14ea1552c349/edit


    SC_DIR=/usr/local/opt/schemacrawler
    java -cp $(echo $SC_DIR/lib/*.jar | tr ' ' ':'):$SC_DIR/config \
    schemacrawler.Main "$@"
  11. dannguyen revised this gist Jun 15, 2018. 1 changed file with 94 additions and 6 deletions.
    100 changes: 94 additions & 6 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    # Generating cool SQLite database diagramswith schemacrawler on Mac OS
    # Generating cool SQLite database diagrams with schemacrawler on Mac OS

    *This was tested on MacOS 10.13*

    [schemacrawler is a free and open-source database schema discovery and comprehension tool](http://www.schemacrawler.com/).

    It can be used from the command-line to generate schema diagrams like these:

    ![image](https://user-images.githubusercontent.com/121520/41448959-de545a74-7012-11e8-99f9-520d76a683b8.png)



    ## Install graphviz dependency

    @@ -20,18 +25,101 @@ The latest releases can be found on the Github page:
    https://github.com/schemacrawler/SchemaCrawler/releases/

    ```sh
    curl -Lo /tmp/schemacrawler-14.21.02-distribution.zip \
    https://github.com/schemacrawler/SchemaCrawler/releases/download/v14.21.02/schemacrawler-14.21.02-distribution.zip
    _SCH_VERSION='14.21.02'
    _SCH_BNAME="schemacrawler-${_SCH_VERSION}-distribution"
    _SCH_TNAME="/tmp/${SCH_BNAME}.zip"
    _SCH_URL="https://github.com/schemacrawler/SchemaCrawler/releases/download/v${_SCH_VERSION}/${_SCH_BNAME}.zip"
    _SCH_DIR='/usr/local/opt/schemacrawler'
    _SCH_SH="${_SCH_DIR}/schemacrawler-macos-opt.sh"

    curl -Lo ${_SCH_TNAME} ${_SCH_URL}

    unzip ${_SCH_TNAME}

    mkdir -p ${_SCH_DIR}
    cp -r /tmp/${_SCH_BNAME}/_schemacrawler/ /usr/local/opt/schemacrawler/

    # create the shell script
    echo '#!/usr/bin/env bash' > ${_SCH_SH}
    echo "SC_DIR=${_SCH_DIR}" >> ${_SCH_SH}
    echo "java -cp \$(echo \$SC_DIR/lib/*.jar | tr ' ' ':'):\$SC_DIR/config schemacrawler.Main \"\$@\"" \
    >> ${_SCH_SH}

    # make it executable
    chmod +x ${_SCH_SH}

    # symlink it
    ln -sf ${_SCH_SH} /usr/local/bin/schemacrawler

    ```

    mkdir -p /usr/local/opt/schemacrawler

    unzip /tmp/schemacrawler-14.21.02-distribution.zip -d /usr/local/opt/schemacrawler

    ln -s /usr/local/opt/schemacrawler/schemacrawler-14.21.02-distribution/_schemacrawler/schemacrawler.sh /usr/local/bin/schemacrawler
    ## General usage

    ```sh
    schemacrawler -server sqlite \
    -database DBNAME.sqlite \
    -user -password \
    -infolevel standard \
    -command schema \
    -outputformat png \
    -outputfile OUTPUT_IMAGE_FILE.png
    ```


    ### Bootload a database

    Just in case you don't have a database to playround with

    ```sh
    echo '''
    DROP TABLE IF EXISTS business;
    DROP TABLE IF EXISTS inspection;
    DROP TABLE IF EXISTS violation;
    CREATE TABLE business (
    business_id TEXT,
    name TEXT,
    address TEXT,
    city TEXT,
    postal_code TEXT,
    latitude DECIMAL,
    longitude DECIMAL,
    phone_number TEXT,
    application_date TEXT,
    owner_name TEXT
    );
    CREATE TABLE inspection (
    business_id TEXT,
    "Score" NUMERIC,
    date TEXT NOT NULL,
    type TEXT NOT NULL,
    FOREIGN KEY(business_id) REFERENCES business(business_id)
    );
    CREATE TABLE violation (
    business_id TEXT,
    date TEXT,
    "ViolationTypeID" TEXT,
    risk_category TEXT,
    description TEXT,
    FOREIGN KEY(business_id, date) REFERENCES inspection(business_id, date)
    );''' \
    | sqlite3 /tmp/tmpdb.sqlite
    ```


    ```
    schemacrawler -server sqlite \
    -database /tmp/tmpdb.sqlite \
    -user -password \
    -infolevel standard \
    -command schema \
    -outputformat png \
    -outputfile /tmp/mytmpdb.png
    ```



  12. dannguyen revised this gist Jun 15, 2018. 2 changed files with 8 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +0,0 @@
    #!/bin/sh
    SC_DIR=`dirname $0`
    java -cp $(echo $SC_DIR/lib/*.jar | tr ' ' ':'):$SC_DIR/config schemacrawler.Main "$@"
    8 changes: 8 additions & 0 deletions schemacrawler-macos-opt.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #!/usr/bin/env bash
    # A shell script customized for modern MacOS, which assumes /usr/local/bin and /usr/local/opt exist
    # https://gist.github.com/dannguyen/f056d05bb7fec408bb7c14ea1552c349/edit


    SC_DIR=/usr/local/opt/schemacrawler
    java -cp $(echo $SC_DIR/lib/*.jar | tr ' ' ':'):$SC_DIR/config \
    schemacrawler.Main "$@"
  13. dannguyen created this gist Jun 15, 2018.
    3 changes: 3 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    #!/bin/sh
    SC_DIR=`dirname $0`
    java -cp $(echo $SC_DIR/lib/*.jar | tr ' ' ':'):$SC_DIR/config schemacrawler.Main "$@"
    40 changes: 40 additions & 0 deletions schemacrawler-sqlite-macos-howto.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # Generating cool SQLite database diagramswith schemacrawler on Mac OS

    *This was tested on MacOS 10.13*

    [schemacrawler is a free and open-source database schema discovery and comprehension tool](http://www.schemacrawler.com/).


    ## Install graphviz dependency

    For schema drawing, `schemacrawler` uses graphviz, which can be installed via homebrew:

    ```sh
    brew install graphviz
    ```

    ## Install schemacrawler

    The latest releases can be found on the Github page:

    https://github.com/schemacrawler/SchemaCrawler/releases/

    ```sh
    curl -Lo /tmp/schemacrawler-14.21.02-distribution.zip \
    https://github.com/schemacrawler/SchemaCrawler/releases/download/v14.21.02/schemacrawler-14.21.02-distribution.zip

    mkdir -p /usr/local/opt/schemacrawler

    unzip /tmp/schemacrawler-14.21.02-distribution.zip -d /usr/local/opt/schemacrawler

    ln -s /usr/local/opt/schemacrawler/schemacrawler-14.21.02-distribution/_schemacrawler/schemacrawler.sh /usr/local/bin/schemacrawler