From 0d40f74503f0be72988407399d719bfe708de75f Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 5 Feb 2021 20:14:43 +0100 Subject: [PATCH] Initial commit --- commands.load | 3 +++ mysql.sql | 11 +++++++++++ psql.sql | 5 +++++ shell.nix | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 commands.load create mode 100644 mysql.sql create mode 100644 psql.sql create mode 100644 shell.nix diff --git a/commands.load b/commands.load new file mode 100644 index 0000000..0491990 --- /dev/null +++ b/commands.load @@ -0,0 +1,3 @@ +LOAD DATABASE + FROM mysql://odyfo:rajjout@unix:/.mysql/mysql.sock/odyfo + INTO postgresql://odyfo:rajjout@/odyfo diff --git a/mysql.sql b/mysql.sql new file mode 100644 index 0000000..f28fc08 --- /dev/null +++ b/mysql.sql @@ -0,0 +1,11 @@ +CREATE DATABASE IF NOT EXISTS odyfo CHARACTER SET utf8mb4; + +CREATE USER IF NOT EXISTS odyfo IDENTIFIED BY 'rajjout'; + +GRANT USAGE ON *.* TO odyfo@localhost IDENTIFIED BY 'rajjout'; + +GRANT ALL PRIVILEGES ON odyfo.* TO odyfo@localhost; + +USE odyfo; + +source origin_db.sql; diff --git a/psql.sql b/psql.sql new file mode 100644 index 0000000..d9b2a1d --- /dev/null +++ b/psql.sql @@ -0,0 +1,5 @@ +CREATE ROLE odyfo WITH LOGIN PASSWORD 'rajjout'; + +CREATE DATABASE odyfo WITH OWNER odyfo; + +CREATE DATABASE test_odyfo WITH OWNER odyfo; diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..048ab84 --- /dev/null +++ b/shell.nix @@ -0,0 +1,39 @@ +{ pkgs ? import { } }: + +with pkgs; + +let + mysql_file = "mysql.sql"; + psql_file = "psql.sql"; + mysql_dir = "$(pwd)/.mysql"; + psql_dir = "$(pwd)/.pgdata"; + socket = "${mysql_dir}/mysql.sock"; + +in mkShell { + buildInputs = [ mysql57 postgresql pgloader ]; + + shellHook = '' + trap "kill 0" EXIT + export PGDATA="${psql_dir}" + export PGHOST="${psql_dir}" + + # MySQL initialization + if [ ! -d ${mysql_dir} ]; then + mysqld --datadir="${mysql_dir}" --socket="${socket}" --initialize-insecure + fi + mysqld --datadir="${mysql_dir}" --socket="${socket}" --skip-networking & + sleep 1 + + # PostgreSQL initialization + if [ ! -d ${psql_dir} ]; then + initdb --auth-local=trust --no-locale --encoding=UTF8 + fi + pg_ctl start -o "--unix_socket_directories=${psql_dir} --listen_addresses='''" + + mysql --socket="${socket}" -u root < ${mysql_file} + psql -d postgres -f ${psql_file} + + alias mysql='mysql --socket="${socket}" -u root' + alias psql='psql -d postgres' + ''; +}