add fix_collation_mismatch function for db container

This commit is contained in:
2025-09-23 15:57:48 +02:00
parent 9d1d89ff81
commit fde3efb0d0

76
abra.sh
View File

@ -21,8 +21,7 @@ export PG_BACKUP_VERSION=v2
export ENTRYPOINT_CSS_VERSION=v1
customize() {
if [ -z "$1" ]
then
if [ -z "$1" ]; then
echo "Usage: ... customize <assets_path>"
exit 1
fi
@ -35,9 +34,8 @@ customize() {
done
}
shell(){
if [ -z "$1" ]
then
shell() {
if [ -z "$1" ]; then
echo "Usage: ... shell <python code>"
exit 1
fi
@ -45,8 +43,7 @@ shell(){
}
import_user() {
if [ -z "$1" ]
then
if [ -z "$1" ]; then
echo "Usage: ... import_user <users.csv>"
exit 1
fi
@ -57,7 +54,7 @@ import_user() {
}
_import_user() {
/manage.py shell -c """
/manage.py shell -c """
import csv
new_user = User()
with open('/tmp/$1', newline='') as file:
@ -85,9 +82,9 @@ with open('/tmp/$1', newline='') as file:
}
set_admin_pass() {
password=$(cat /run/secrets/admin_pass)
token=$(cat /run/secrets/admin_token)
/manage.py shell -c """
password=$(cat /run/secrets/admin_pass)
token=$(cat /run/secrets/admin_token)
/manage.py shell -c """
import time
i = 0
while (not User.objects.filter(username='akadmin')):
@ -160,7 +157,7 @@ apply_blueprint() {
}
blueprint_state() {
/manage.py shell -c """
/manage.py shell -c """
import time
blueprint_state=$1
blueprint_path='$2'
@ -178,9 +175,9 @@ print(f'{blueprint.name} enabled: {blueprint.enabled}')
}
# This function adds each application with its name, slug and group if passed
add_applications(){
export APPLICATIONS
/manage.py shell -c """
add_applications() {
export APPLICATIONS
/manage.py shell -c """
import json
import os
if os.environ['APPLICATIONS'] == '':
@ -207,7 +204,7 @@ for name, details in applications.items():
## This function is for renaming apps - usage: rename "old name" "new name"
rename() {
/manage.py shell -c """
/manage.py shell -c """
old_name = '$1'
new_name = '$2' if '$2' else old_name
@ -221,39 +218,35 @@ else:
""" 2>&1 | quieten
}
quieten(){
quieten() {
# 'SyntaxWarning|version_regex|"http\['
# is a workaround to get rid of some verbose syntax warnings, this might be fixed with another version
grep -Pv '"level": "(info|debug)"|SyntaxWarning|version_regex|"http\[|RuntimeWarning:'
}
add_email_templates(){
for file_path in "$@"; do
add_email_templates() {
for file_path in "$@"; do
echo copy template $file_path
abra app cp $APP_NAME $file_path app:/templates/
done
done
}
set_icons(){
if [ -n "$1" ]
then
APP_ICONS="$1"
fi
for icon in $APP_ICONS; do
set_icons() {
if [ -n "$1" ]; then
APP_ICONS="$1"
fi
for icon in $APP_ICONS; do
app=$(echo $icon | cut -d ":" -f1)
file_path=$(eval echo $(echo $icon | cut -d ":" -f2))
file=$(basename $file_path)
echo copy icon $file_path for $app
abra app cp $APP_NAME $file_path app:/media/
abra app cmd -T $APP_NAME app set_app_icon $app /media/$file
done
done
}
set_extra_icons(){
if [ -z "$EXTRA_ICONS" ]
then
set_extra_icons() {
if [ -z "$EXTRA_ICONS" ]; then
echo "Variable EXTRA_ICONS is not set"
exit 1
fi
@ -268,8 +261,8 @@ for key, value in json.loads(os.environ['EXTRA_ICONS']).items():
}
set_app_icon() {
TOKEN=$(cat /run/secrets/admin_token)
python -c """
TOKEN=$(cat /run/secrets/admin_token)
python -c """
import requests
import os
my_token = '$TOKEN'
@ -288,18 +281,18 @@ with open(icon_path, 'rb') as img:
}
blueprint_cleanup() {
/manage.py shell -c """
/manage.py shell -c """
delete_flows = ['default-recovery-flow' , 'custom-authentication-flow' , 'invitation-enrollment-flow' , 'initial-setup']
Flow.objects.filter(slug__in=delete_flows).delete()
Stage.objects.filter(flow=None).delete()
Prompt.objects.filter(promptstage=None).delete()
Brand.objects.filter(default=True).delete()
""" 2>&1 | quieten
apply_blueprints
apply_blueprints
}
get_certificate() {
/manage.py shell -c """
/manage.py shell -c """
provider_name='$1'
if not provider_name:
print('no Provider Name given')
@ -312,7 +305,14 @@ print(''.join(cert.certificate_data.splitlines()[1:-1]))
}
get_user_uid() {
/manage.py shell -c """
/manage.py shell -c """
print(User.objects.filter(username='$1').first().uid)
""" 2>&1 | quieten
}
fix_collation_mismatch() {
psql -U ${POSTGRES_USER} -d authentik -c "ALTER DATABASE authentik REFRESH COLLATION VERSION;"
psql -U ${POSTGRES_USER} -d authentik -c "REINDEX DATABASE authentik;"
psql -U ${POSTGRES_USER} -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"
psql -U ${POSTGRES_USER} -d postgres -c "REINDEX DATABASE postgres;"
}