1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/castopod_ynh.git synced 2024-09-03 18:16:14 +02:00

Run SQL migrations for v1.10.5

This commit is contained in:
orhtej2 2024-03-13 22:02:00 +01:00
parent 788f091c3f
commit 9f685a9100
2 changed files with 146 additions and 140 deletions

2
conf/sql/v1.10.5.sql Normal file
View file

@ -0,0 +1,2 @@
INSERT INTO `cp_platforms` (`slug`, `type`, `label`, `home_url`, `submit_url`) VALUES
('bluesky', 'social', 'Bluesky', 'https://bsky.app/', 'https://bsky.app/');

View file

@ -1,140 +1,144 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# GENERIC START # GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# If fpm_footprint doesn't exist, create it # If fpm_footprint doesn't exist, create it
if [ -z "${fpm_footprint:-}" ]; then if [ -z "${fpm_footprint:-}" ]; then
fpm_footprint=low fpm_footprint=low
ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint
fi fi
# If fpm_free_footprint doesn't exist, create it # If fpm_free_footprint doesn't exist, create it
if [ -z "${fpm_free_footprint:-}" ]; then if [ -z "${fpm_free_footprint:-}" ]; then
fpm_free_footprint=0 fpm_free_footprint=0
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint
fi fi
# If fpm_usage doesn't exist, create it # If fpm_usage doesn't exist, create it
if [ -z "${fpm_usage:-}" ]; then if [ -z "${fpm_usage:-}" ]; then
fpm_usage=low fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage
fi fi
# If redis_db doesn't exist, create it # If redis_db doesn't exist, create it
if [ -z "${redis_db:-}" ]; then if [ -z "${redis_db:-}" ]; then
# Configure redis # Configure redis
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
fi fi
#================================================= #=================================================
# MOVE DATA TO __DATA_DIR__ # MOVE DATA TO __DATA_DIR__
#================================================= #=================================================
if ynh_compare_current_package_version --comparison le --version "1.1.2~ynh2"; then if ynh_compare_current_package_version --comparison le --version "1.1.2~ynh2"; then
ynh_script_progression --message="Moving data..." --weight=3 ynh_script_progression --message="Moving data..." --weight=3
mkdir -p $data_dir/media mkdir -p $data_dir/media
cp -rf $install_dir/public/media/* $data_dir/media cp -rf $install_dir/public/media/* $data_dir/media
chmod -R 750 $data_dir chmod -R 750 $data_dir
chown -R $app:www-data $data_dir chown -R $app:www-data $data_dir
ynh_secure_remove --file="$install_dir/public/media" ynh_secure_remove --file="$install_dir/public/media"
ynh_script_progression --message="Fixing migrations..." --weight=1 ynh_script_progression --message="Fixing migrations..." --weight=1
# this will fail is `cp-install` was not run on prev version - just ignore, DB schema is (re)generated later. # this will fail is `cp-install` was not run on prev version - just ignore, DB schema is (re)generated later.
ynh_mysql_execute_as_root --database=$db_name --sql="UPDATE cp_migrations SET class='Media\\\\Database\\\\Migrations\\\\AddMedia', namespace='Media' where class='App\\\\Database\\\\Migrations\\\\AddMedia'" || true ynh_mysql_execute_as_root --database=$db_name --sql="UPDATE cp_migrations SET class='Media\\\\Database\\\\Migrations\\\\AddMedia', namespace='Media' where class='App\\\\Database\\\\Migrations\\\\AddMedia'" || true
elif ynh_compare_current_package_version --comparison lt --version "1.6.5~ynh2"; then elif ynh_compare_current_package_version --comparison lt --version "1.6.5~ynh2"; then
chown -R $app:www-data $data_dir chown -R $app:www-data $data_dir
fi fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
# 1.7.1~ynh2 accidently shipped 1.6.5, force upgrade on that version even if it's theoretically the same upstream release # 1.7.1~ynh2 accidently shipped 1.6.5, force upgrade on that version even if it's theoretically the same upstream release
if [ "$upgrade_type" == "UPGRADE_APP" ] || ynh_compare_current_package_version --comparison eq --version "1.7.1~ynh2" if [ "$upgrade_type" == "UPGRADE_APP" ] || ynh_compare_current_package_version --comparison eq --version "1.7.1~ynh2"
then then
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 ynh_setup_source --dest_dir="$install_dir" --full_replace=1
fi fi
chmod -R o-rwx "$install_dir" chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir" chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression --message="Updating a configuration file..." --weight=1
# Create a dedicated PHP-FPM config # Create a dedicated PHP-FPM config
ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
ynh_add_config --template="cron" --destination="/etc/cron.d/$app" ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app" chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app" chmod 644 "/etc/cron.d/$app"
#================================================= #=================================================
# CONFIGURE CASTOPOD # CONFIGURE CASTOPOD
#================================================= #=================================================
ynh_script_progression --message="Configuring $app..." --weight=1 ynh_script_progression --message="Configuring $app..." --weight=1
ynh_add_config --template=".env.example" --destination="$install_dir/.env" ynh_add_config --template=".env.example" --destination="$install_dir/.env"
chmod 600 $install_dir/.env chmod 600 $install_dir/.env
chown $app:www-data "$install_dir/.env" chown $app:www-data "$install_dir/.env"
#================================================= #=================================================
# RUN MIGRATIONS # RUN MIGRATIONS
#================================================= #=================================================
ynh_script_progression --message="Configuring $app database..." --weight=1 ynh_script_progression --message="Configuring $app database..." --weight=1
pushd $install_dir pushd $install_dir
ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark cache:clear ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark cache:clear
ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark castopod:database-update ynh_exec_warn_less ynh_exec_as $app php${phpversion} spark castopod:database-update
popd popd
if ynh_compare_current_package_version --comparison le --version "1.6.5~ynh1"; then if ynh_compare_current_package_version --comparison le --version "1.6.5~ynh1"; then
# cf https://code.castopod.org/adaures/castopod/-/releases/v1.5.2 # cf https://code.castopod.org/adaures/castopod/-/releases/v1.5.2
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.5.2.sql" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.5.2.sql"
# cf https://code.castopod.org/adaures/castopod/-/releases/v1.6.1 # cf https://code.castopod.org/adaures/castopod/-/releases/v1.6.1
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.6.1.sql" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.6.1.sql"
fi fi
if ynh_compare_current_package_version --comparison lt --version "1.7.3~ynh1"; then if ynh_compare_current_package_version --comparison lt --version "1.7.3~ynh1"; then
# cf https://code.castopod.org/adaures/castopod/-/releases/v1.7.3 # cf https://code.castopod.org/adaures/castopod/-/releases/v1.7.3
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.7.3.sql" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.7.3.sql"
fi fi
if ynh_compare_current_package_version --comparison lt --version "1.8.2~ynh1"; then if ynh_compare_current_package_version --comparison lt --version "1.8.2~ynh1"; then
# cf https://code.castopod.org/adaures/castopod/-/releases/v1.7.3 # cf https://code.castopod.org/adaures/castopod/-/releases/v1.8.2
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.8.0.sql" ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.8.0.sql"
fi fi
if ynh_compare_current_package_version --comparison lt --version "1.10.5~ynh1"; then
#================================================= # cf https://code.castopod.org/adaures/castopod/-/releases/v1.10.5
# END OF SCRIPT ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "../conf/sql/v1.10.5.sql"
#================================================= fi
ynh_script_progression --message="Upgrade of $app completed" --last #=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last