From 04d1fbf936f04f198c40aaca161bf11e900e1fe0 Mon Sep 17 00:00:00 2001
From: Okhin <okhin@okhin.fr>
Date: Mon, 29 Oct 2018 18:29:52 +0100
Subject: [PATCH] Moving users around

---
 scripts/import_users.sh | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100755 scripts/import_users.sh

diff --git a/scripts/import_users.sh b/scripts/import_users.sh
new file mode 100755
index 0000000..55089ff
--- /dev/null
+++ b/scripts/import_users.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+# Cette monstruosité utilise un import/export par CSV de psql vers mariadb des utilisqteurs nécessaires. On pipe l'un dans l'autre. Il faut exécuter ce script avec des droits sudo.
+PSQL_QUERY="COPY (SELECT DISTINCT ON (auth_user.email) email, auth_user.username pseudo FROM auth_user WHERE email NOT LIKE '' AND is_active = 't') TO STDOUT WITH (FORMAT CSV, HEADER, DELIMITER ',');"
+MYSQL_QUERY="LOAD DATA LOCAL INFILE '/dev/stdin' INTO TABLE users FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\"' ESCAPED BY '\\"' LINES TERMINATED BY '\n' IGNORE 1 LINES (email, pseudo);"
+sudo -u postgres psql -d soutien -c "$PSQL_QUERY" | mysql $SQL_DATABASE -u $SQL_USER -p$SQL_PASSWORD --local-infile=1 -e "$MYSQL_QUERY"
-- 
GitLab