postgres_migration/shell.nix

33 lines
647 B
Nix
Raw Normal View History

2021-02-05 20:14:43 +01:00
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
sql_file = "psql_creation.sql";
data_dir = "$(pwd)/.pgdata";
origin = "databases/odyfo.db";
2021-02-05 20:14:43 +01:00
in mkShell {
buildInputs = [ postgresql sqlite ];
2021-02-05 20:14:43 +01:00
shellHook = ''
trap "kill 0" EXIT
export PGDATA="${data_dir}"
export PGHOST="${data_dir}"
2021-02-05 20:14:43 +01:00
if [ ! -d ${data_dir} ]; then
2021-02-05 20:14:43 +01:00
initdb --auth-local=trust --no-locale --encoding=UTF8
fi
2021-02-05 21:16:35 +01:00
if ! pg_ctl status; then
pg_ctl start -o "--unix_socket_directories=${data_dir} --listen_addresses='''"
2021-02-05 21:16:35 +01:00
fi
2021-02-05 20:14:43 +01:00
psql -d postgres -f ${sql_file}
2021-02-05 20:14:43 +01:00
alias psql='psql -d postgres'
alias nuke='rm -rf ${data_dir}'
2021-02-05 20:14:43 +01:00
'';
}