Add MySQL and alembic
This commit is contained in:
parent
ad63122878
commit
b5d4ed519d
|
@ -0,0 +1,11 @@
|
|||
CREATE DATABASE odyfo CHARACTER SET utf8mb4;
|
||||
|
||||
CREATE DATABASE test_odyfo CHARACTER SET utf8mb4;
|
||||
|
||||
USE odyfo;
|
||||
|
||||
source databases/production_db.sql;
|
||||
|
||||
USE test;
|
||||
|
||||
source databases/test_db.sql;
|
|
@ -1,5 +1,3 @@
|
|||
CREATE ROLE odyfo WITH LOGIN PASSWORD 'rajjout';
|
||||
CREATE DATABASE odyfo;
|
||||
|
||||
CREATE DATABASE odyfo WITH OWNER odyfo;
|
||||
|
||||
CREATE DATABASE test_odyfo WITH OWNER odyfo;
|
||||
CREATE DATABASE test_odyfo;
|
||||
|
|
51
shell.nix
51
shell.nix
|
@ -3,34 +3,59 @@
|
|||
with pkgs;
|
||||
|
||||
let
|
||||
sql_file = "psql_creation.sql";
|
||||
data_dir = "$(pwd)/.pgdata";
|
||||
origin = "odyfo.db";
|
||||
psql_file = "psql_creation.sql";
|
||||
psql_dir = "$(pwd)/.pgdata";
|
||||
mysql_file = "databases/mysql_creation.sql";
|
||||
mysql_dir = "$(pwd)/.mysql";
|
||||
socket = "${mysql_dir}/mysql.sock";
|
||||
origin = "mysql:///odyfo";
|
||||
destination = "postgresql:///odyfo";
|
||||
|
||||
in mkShell {
|
||||
buildInputs = [ postgresql pgloader ];
|
||||
buildInputs = [
|
||||
postgresql
|
||||
mysql57
|
||||
pgloader
|
||||
python38Packages.alembic
|
||||
python38Packages.pymysql
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
trap "kill 0" EXIT
|
||||
export PGDATA="${data_dir}"
|
||||
export PGHOST="${data_dir}"
|
||||
export PGDATA="${psql_dir}"
|
||||
export PGHOST="${psql_dir}"
|
||||
|
||||
if [ ! -d ${data_dir} ]; then
|
||||
# Initialize PostgreSQL
|
||||
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=${data_dir} --listen_addresses='''"
|
||||
pg_ctl start -o "--unix_socket_directories=${psql_dir} --listen_addresses='''"
|
||||
fi
|
||||
|
||||
if [ ! -d ${data_dir} ]; then
|
||||
psql -d postgres -f ${sql_file}
|
||||
if [ ! -d ${psql_dir} ]; then
|
||||
psql -d postgres -f ${psql_file}
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
if [ ! -d ${mysql_dir} ]; then
|
||||
mysql --socket="${socket}" -u root < ${mysql_file}
|
||||
fi
|
||||
|
||||
alias psql='psql -d postgres'
|
||||
alias nuke='rm -rf ${data_dir}'
|
||||
alias mysql='mysql --socket="${socket}" -u root'
|
||||
alias nuke='rm -rf ${psql_dir} ${mysql_dir}'
|
||||
|
||||
pgloader ${origin} postgresql:///odyfo
|
||||
pg_dump odyfo > migrated_db.sql
|
||||
alembic upgrade head
|
||||
pgloader ${origin} ${destination}
|
||||
pg_dump odyfo > databases/migrated_db.sql
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue