Compare commits
1 Commits
13336f8c17
...
1232ba036e
Author | SHA1 | Date |
---|---|---|
coolneng | 1232ba036e |
57
shell.nix
57
shell.nix
|
@ -2,15 +2,56 @@
|
||||||
|
|
||||||
with pkgs;
|
with pkgs;
|
||||||
|
|
||||||
mkShell {
|
let
|
||||||
buildInputs = [ python27 python27Packages.virtualenv ];
|
psql_file = "psql_creation.sql";
|
||||||
|
psql_dir = "$(pwd)/.pgdata";
|
||||||
|
mysql_file = "mysql_creation.sql";
|
||||||
|
mysql_dir = "$(pwd)/.mysql";
|
||||||
|
socket = "${mysql_dir}/mysql.sock";
|
||||||
|
origin = "mysql:///odyfo";
|
||||||
|
destination = "postgresql:///odyfo";
|
||||||
|
|
||||||
|
in mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
postgresql
|
||||||
|
mysql57
|
||||||
|
pgloader
|
||||||
|
python38Packages.alembic
|
||||||
|
python38Packages.pymysql
|
||||||
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
# Workaround to use pip
|
trap "kill 0" EXIT
|
||||||
SOURCE_DATE_EPOCH=$(date +%s)
|
export PGDATA="${psql_dir}"
|
||||||
virtualenv .venv
|
export PGHOST="${psql_dir}"
|
||||||
export PATH=$PWD/.venv/bin:$PATH
|
|
||||||
pip install etlalchemy
|
# Initialize PostgreSQL
|
||||||
pip install psycopg2
|
if [ ! -d ${psql_dir} ]; then
|
||||||
|
initdb --auth-local=trust --no-locale --encoding=UTF8
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! pg_ctl status; then
|
||||||
|
pg_ctl start -o "--unix_socket_directories=${psql_dir} --listen_addresses='''"
|
||||||
|
fi
|
||||||
|
|
||||||
|
psql -d postgres -f ${psql_file}
|
||||||
|
|
||||||
|
# Initialize MySQL
|
||||||
|
if [ ! -d ${mysql_dir} ]; then
|
||||||
|
mysqld --datadir="${mysql_dir}" --socket="${socket}" --initialize-insecure
|
||||||
|
fi
|
||||||
|
|
||||||
|
mysqld --datadir="${mysql_dir}" --socket="${socket}" --skip-networking &
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
mysql --socket="${socket}" -u root < ${mysql_file}
|
||||||
|
|
||||||
|
alias psql='psql -d postgres'
|
||||||
|
alias mysql='mysql --socket="${socket}" -u root'
|
||||||
|
alias nuke='rm -rf ${psql_dir} ${mysql_dir}'
|
||||||
|
|
||||||
|
alembic upgrade head
|
||||||
|
pgloader ${origin} ${destination}
|
||||||
|
pg_dump odyfo > databases/migrated_db.sql
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue