Add a script to generate a list of deleted users uids
authorSimon Poole <simon@poole.ch>
Wed, 5 Sep 2018 13:20:11 +0000 (15:20 +0200)
committerSimon Poole <simon@poole.ch>
Wed, 5 Sep 2018 13:20:11 +0000 (15:20 +0200)
cookbooks/planet/recipes/replication.rb
cookbooks/planet/templates/default/replication.cron.erb
cookbooks/planet/templates/default/users-deleted.erb [new file with mode: 0644]

index feedac7dab59fd41f2f092e771a2b2378ea2f360..770d52c7c5362a638d68cfe907ebaf9ec171ee60 100644 (file)
@@ -69,6 +69,13 @@ template "/usr/local/bin/users-agreed" do
   mode 0o755
 end
 
+template "/usr/local/bin/users-deleted" do
+  source "users-deleted.erb"
+  owner "root"
+  group "root"
+  mode 0o755
+end
+
 remote_directory "/store/planet/replication" do
   source "replication-cgi"
   owner "root"
index 5300781be048de6043e3a223a766ff3b7a52cad7..0ccffdd1e27780d75e067387883bc0f5bf85cf89 100644 (file)
@@ -5,6 +5,7 @@ TZ=UTC
 MAILTO=zerebubuth@gmail.com
 
 0 7 * * * planet /usr/local/bin/users-agreed
+0 17 * * * planet /usr/local/bin/users-deleted
 * * * * * planet /usr/local/bin/replicate-changesets /etc/replication/changesets.conf
 
 MAILTO=brett@bretth.com
diff --git a/cookbooks/planet/templates/default/users-deleted.erb b/cookbooks/planet/templates/default/users-deleted.erb
new file mode 100644 (file)
index 0000000..6360d28
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+T=$(mktemp -d -t -p /var/tmp users.XXXXXXXXXX)
+
+# use the same as for the users-agreed template
+export PGPASSFILE=/etc/replication/users-agreed.conf
+
+echo "# user IDs of deleted users. " > $T/users_deleted
+psql -h <%= node[:web][:readonly_database_host] %> -U planetdiff -t -c "select id from users where status='deleted' by id asc" openstreetmap >> $T/users_deleted
+
+if cmp -s "${T}/users_deleted "/store/planet/users_deleted.txt"; then
+  : # do nothing
+else
+  cp $T/users_deleted /store/planet/users_deleted.txt
+fi
+
+rm -rf $T