Skip to content

Commit

Permalink
Improve psql
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain committed Dec 8, 2024
1 parent 7fc549f commit 0000d64
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
11 changes: 5 additions & 6 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "Immich"
description.en = "Photo and video backup solution directly from your mobile phone"
description.fr = "Sauvegarde de photos et de vidéos directement depuis votre mobile"

version = "1.122.1~ynh1"
version = "1.122.1~ynh2"

maintainers = ["ewilly"]

Expand Down Expand Up @@ -126,10 +126,9 @@ ram.runtime = "500M"
"libpq-dev",
"postgresql-16",
"postgresql-16-pgvector",
"postgresql-client-16",
"postgresql-common",
"postgresql-client-common"
"postgresql-client-16"
]

[resources.database]
type = "postgresql"
# Commented to avoid provisionning a db on wrong cluster
#[resources.database]
#type = "postgresql"
25 changes: 21 additions & 4 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ postgresql_version() {
ynh_read_manifest "resources.apt.extras.postgresql.packages" \
| grep -o 'postgresql-[0-9][0-9]-pgvector' | head -n1 | cut -d'-' -f2
}
postgresql_cluster_port() {
pg_lsclusters --no-header | grep "^$postgresql_version" | cut -d' ' -f3
}

# Retrieve full latest python version from major version
# usage: py_latest_from_major --python="3.8"
Expand Down Expand Up @@ -295,9 +298,7 @@ myynh_drop_psql_db() {
# Dump the database
myynh_dump_psql_db() {
local db_port=$(ynh_app_setting_get --key=psql_port)
sudo --login --user=postgres pg_dump --port="$db_port" --dbname="$app" > db.sql
sudo --login --user=postgres pg_dump --cluster="$(postgresql_version)/main" --dbname="$app" > db.sql
}
# Restore the database
Expand All @@ -312,7 +313,7 @@ myynh_restore_psql_db() {
# Set permissions
myynh_set_permissions () {
myynh_set_permissions() {
chown -R $app: "$install_dir"
chmod u=rwX,g=rX,o= "$install_dir"
chmod -R o-rwx "$install_dir"
Expand All @@ -327,3 +328,19 @@ myynh_set_permissions () {
chown -R $app: "/var/log/$app"
chmod u=rw,g=r,o= "/var/log/$app"
}
myynh_set_default_psql_cluster_to_debian_default() {
local default_port=5432
local config_file="/etc/postgresql-common/user_clusters"
#retrieve informations about default psql cluster
default_psql_version=$(pg_lsclusters --no-header | grep "$default_port" | cut -d' ' -f1)
default_psql_cluster=$(pg_lsclusters --no-header | grep "$default_port" | cut -d' ' -f2)
default_psql_database=$(pg_lsclusters --no-header | grep "$default_port" | cut -d' ' -f5)
# Remove non commented lines
sed -i'.bak' -e '/^#/!d' "$config_file"
# Add new line USER GROUP VERSION CLUSTER DATABASE
echo -e "* * $default_psql_version $default_psql_cluster $default_psql_database" >> "$config_file"
}
2 changes: 2 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ynh_app_setting_set --key=psql_pwd --value="$db_pwd"
ynh_app_setting_set --key=psql_version --value="$(postgresql_version)"
ynh_app_setting_set --key=psql_port --value="$db_port"

myynh_set_default_psql_cluster_to_debian_default

#=================================================
# MAKE INSTALL
#=================================================
Expand Down
2 changes: 2 additions & 0 deletions scripts/restore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ myynh_update_psql_db
myynh_create_psql_db
myynh_restore_psql_db

myynh_set_default_psql_cluster_to_debian_default

#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
Expand Down
12 changes: 11 additions & 1 deletion scripts/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ynh_script_progression "Ensuring downward compatibility..."

if ynh_app_upgrading_from_version_before 1.118.2~ynh1
then
if ynh_hide_warnings yunohost service status "$app-microservices" >/dev/null; then
if ynh_hide_warnings yunohost service status "$app-microservices" >/dev/null
then
yunohost service remove "$app-microservices"
fi
ynh_config_remove_systemd "$app-microservices"
Expand All @@ -21,6 +22,13 @@ then
ynh_app_setting_delete --key="checksum__etc_systemd_system_immich-microservices.service"
fi

if ynh_app_upgrading_from_version_before 1.122.1~ynh2
then
ynh_psql_drop_db "$app"
ynh_psql_drop_user "$app"
fi


#=================================================
# STOP SYSTEMD SERVICE
#=================================================
Expand Down Expand Up @@ -64,6 +72,8 @@ ynh_script_progression "Udpating a PostgreSQL database..."

myynh_update_psql_db

myynh_set_default_psql_cluster_to_debian_default

#=================================================
# MAKE INSTALL
#=================================================
Expand Down

0 comments on commit 0000d64

Please sign in to comment.