nix: Install and initialize a Postgres DB For a persistance layer, this change introduces postgresql as dependency. The daemon is started when `nix-shell` is invoked. `pg_ctl stop` is not invoked, and this has to be done by a developer. Data is persisted in a tmp directory, which is added to the ignore file.

zj
Jul 15, 2021, 11:52 AM
EIIUUAKGFBWJJ67QKWXX3X7TC2ASQIAUZV4734C5KQKWNHOVYJGAC

Dependencies

  • [2] W3M3C7CC Initial commit This change includes a very small hello world application server written in Rust using Rocket.rs. Managing dependencies is done with Nix as that works well between Linux and Mac for me.

Change contents

  • edit in shell.nix at line 14
    [2.1152]
    [2.1152]
    # Database
    pkgs.buildPackages.postgresql
  • edit in shell.nix at line 20
    [2.1215]
    [2.1215]
    shellHook = ''
    export PGDATA=$PWD/tmp/postgres_data
    export PGHOST=$PWD/tmp/postgres
    export LOG_PATH=$PWD/tmp/postgres/LOG
    export PGDATABASE=postgres
    export DATABASE_URL="postgresql:///postgres?host=$PGHOST"
    if [ ! -d $PGHOST ]; then
    mkdir -p $PGHOST
    fi
    if [ ! -d $PGDATA ]; then
    echo 'Initializing postgresql database...'
    initdb $PGDATA --auth=trust >/dev/null
    fi
    pg_ctl start -l $LOG_PATH -o "-c listen_addresses= -c unix_socket_directories=$PGHOST"
    '';
  • file addition: .ignore (----------)
    [1.0]
    /target
    /tmp