diff --git a/.helm/.env-example b/.helm/.env-example index d00b1bd226a..7469882c872 100644 --- a/.helm/.env-example +++ b/.helm/.env-example @@ -22,3 +22,4 @@ RESTORE_S3_BUCKET= RESTORE_S3_ACCESS_KEY_ID= RESTORE_S3_ACCESS_KEY= RESTORE_ENCRYPTION_KEY=test +RESTORE_INVITE_SUPPORT_ACCOUNT_TO_INTERESTING_CAMPS=false diff --git a/.helm/deploy-to-cluster.sh b/.helm/deploy-to-cluster.sh index 73988e8b2c3..3d2c52ce12a 100755 --- a/.helm/deploy-to-cluster.sh +++ b/.helm/deploy-to-cluster.sh @@ -85,6 +85,7 @@ for i in 1; do if [ -n $RESTORE_ENCRYPTION_KEY ]; then values="$values --set postgresql.restore.encryptionKey=$RESTORE_ENCRYPTION_KEY" fi + values="$values --set postgresql.restore.inviteSupportAccountToInterestingCamps=$RESTORE_INVITE_SUPPORT_ACCOUNT_TO_INTERESTING_CAMPS" fi for imagespec in "php" "caddy"; do diff --git a/.helm/ecamp3/files/hook_db_restore/.env-example b/.helm/ecamp3/files/hook_db_restore/.env-example index 25e3d47cc75..70d82034be7 100644 --- a/.helm/ecamp3/files/hook_db_restore/.env-example +++ b/.helm/ecamp3/files/hook_db_restore/.env-example @@ -8,3 +8,4 @@ S3_ENDPOINT=https://s3.eu-west-3.amazonaws.com S3_BUCKET= S3_ACCESS_KEY_ID= S3_ACCESS_KEY= +INVITE_SUPPORT_ACCOUNT_TO_INTERESTING_CAMPS=false diff --git a/.helm/ecamp3/files/hook_db_restore/restore-backup.sh b/.helm/ecamp3/files/hook_db_restore/restore-backup.sh index 3b80bba5d86..fe9a77a973f 100644 --- a/.helm/ecamp3/files/hook_db_restore/restore-backup.sh +++ b/.helm/ecamp3/files/hook_db_restore/restore-backup.sh @@ -48,46 +48,47 @@ EOF psql $DATABASE_URL < $sql_file_for_restore - -cat << 'EOF' | psql $DATABASE_URL -CREATE EXTENSION IF NOT EXISTS pgcrypto; - -INSERT INTO camp_collaboration (id, status, role, createtime, - updatetime, userid, campid) - (WITH interesting_camps as ((SELECT c.id - FROM camp c - JOIN activity a on c.id = a.campid - GROUP BY c.id, c.title - ORDER BY count(a.id) DESC - LIMIT 10) - UNION - (SELECT id - FROM ((SELECT c.id - FROM camp c - JOIN activity a on c.id = a.campid - GROUP BY c.id, c.title - ORDER BY count(a.id) DESC) - INTERSECT - (SELECT c.id - FROM camp c - JOIN period p on c.id = p.campid - WHERE p."end" >= now())) as a - LIMIT 10)) - SELECT encode(gen_random_bytes(6), 'hex'), - 'established', - 'manager', - now(), - now(), - u.id, - ic.id - FROM interesting_camps ic, - profile p - JOIN "user" u ON p.id = u.profileid - WHERE p.email IN ( - 'support@ecamp3.ch' - ) - AND ic.id NOT IN (SELECT campid FROM camp_collaboration WHERE userid = u.id)); +if [ "$INVITE_SUPPORT_ACCOUNT_TO_INTERESTING_CAMPS" = "true" ]; then + cat << 'EOF' | psql $DATABASE_URL + CREATE EXTENSION IF NOT EXISTS pgcrypto; + + INSERT INTO camp_collaboration (id, status, role, createtime, + updatetime, userid, campid) + (WITH interesting_camps as ((SELECT c.id + FROM camp c + JOIN activity a on c.id = a.campid + GROUP BY c.id, c.title + ORDER BY count(a.id) DESC + LIMIT 10) + UNION + (SELECT id + FROM ((SELECT c.id + FROM camp c + JOIN activity a on c.id = a.campid + GROUP BY c.id, c.title + ORDER BY count(a.id) DESC) + INTERSECT + (SELECT c.id + FROM camp c + JOIN period p on c.id = p.campid + WHERE p."end" >= now())) as a + LIMIT 10)) + SELECT encode(gen_random_bytes(6), 'hex'), + 'established', + 'manager', + now(), + now(), + u.id, + ic.id + FROM interesting_camps ic, + profile p + JOIN "user" u ON p.id = u.profileid + WHERE p.email IN ( + 'support@ecamp3.ch' + ) + AND ic.id NOT IN (SELECT campid FROM camp_collaboration WHERE userid = u.id)); EOF +fi rm -rf $working_dir/* rm -rf $complete_marker diff --git a/.helm/ecamp3/templates/hook_db_restore.yaml b/.helm/ecamp3/templates/hook_db_restore.yaml index 05ad0683fb2..40a2daea58d 100644 --- a/.helm/ecamp3/templates/hook_db_restore.yaml +++ b/.helm/ecamp3/templates/hook_db_restore.yaml @@ -84,6 +84,8 @@ spec: name: {{ include "hookDbRestore.name" . }} key: encryption-key optional: true + - name: INVITE_SUPPORT_ACCOUNT_TO_INTERESTING_CAMPS + value: {{ .Values.postgresql.restore.inviteSupportAccountToInterestingCamps }} volumeMounts: - mountPath: /tmp/backup-dir name: backup-dir diff --git a/.helm/ecamp3/values.yaml b/.helm/ecamp3/values.yaml index 3cc8034ca87..1e05596065f 100644 --- a/.helm/ecamp3/values.yaml +++ b/.helm/ecamp3/values.yaml @@ -175,6 +175,7 @@ postgresql: bucket: accessKeyId: accessKey: + inviteSupportAccountToInterestingCamps: false encryptionKey: recaptcha: