From 388814bb3f7dad6e097eed0fded51485c3ee1e4f Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 10 Feb 2021 01:26:54 +0100 Subject: [PATCH] Use etlalchemy for the migration --- migration.py | 25 +++++++++++++++++++++++++ shell.nix | 10 +++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 migration.py diff --git a/migration.py b/migration.py new file mode 100644 index 0000000..6544505 --- /dev/null +++ b/migration.py @@ -0,0 +1,25 @@ +from etlalchemy import ETLAlchemySource, ETLAlchemyTarget + +source = ETLAlchemySource( + "sqlite:///databases/odyfo.db", + included_tables=[ + "users", + "cities", + "games", + "payments", + "player_availabilities", + "player_cancel_games", + "purchase_games", + "sports", + "teams", + "user_ratings", + "venue_images", + "venues", + "web_bookings", + ], +) +target = ETLAlchemyTarget( + "postgresql+psycopg2://postgres@localhost/odyfo", drop_database=True +) +target.addSource(source) +target.migrate() diff --git a/shell.nix b/shell.nix index f3bb988..12d1637 100644 --- a/shell.nix +++ b/shell.nix @@ -8,7 +8,7 @@ let origin = "databases/odyfo.db"; in mkShell { - buildInputs = [ postgresql sqlite ]; + buildInputs = [ postgresql python27 python27Packages.virtualenv ]; shellHook = '' trap "kill 0" EXIT @@ -23,10 +23,14 @@ in mkShell { pg_ctl start -o "--unix_socket_directories=${data_dir} --listen_addresses='''" fi - psql -d postgres -f ${sql_file} - alias psql='psql -d postgres' alias nuke='rm -rf ${data_dir}' + # Workaround to use pip + SOURCE_DATE_EPOCH=$(date +%s) + virtualenv .venv + export PATH=$PWD/.venv/bin:$PATH + pip install etlalchemy + pip install psycopg2 ''; }