Skip to content

Commit

Permalink
make invitations to interesting camps optional
Browse files Browse the repository at this point in the history
Issue: #3478
  • Loading branch information
BacLuc committed Jul 31, 2023
1 parent 7d40913 commit 4ce799f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 39 deletions.
1 change: 1 addition & 0 deletions .helm/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .helm/deploy-to-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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
Expand Down
1 change: 1 addition & 0 deletions .helm/ecamp3/files/hook_db_restore/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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
79 changes: 40 additions & 39 deletions .helm/ecamp3/files/hook_db_restore/restore-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
'[email protected]'
)
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 (
'[email protected]'
)
AND ic.id NOT IN (SELECT campid FROM camp_collaboration WHERE userid = u.id));
EOF
fi

rm -rf $working_dir/*
rm -rf $complete_marker
2 changes: 2 additions & 0 deletions .helm/ecamp3/templates/hook_db_restore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .helm/ecamp3/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ postgresql:
bucket:
accessKeyId:
accessKey:
inviteSupportAccountToInterestingCamps: false
encryptionKey:

recaptcha:
Expand Down

0 comments on commit 4ce799f

Please sign in to comment.