mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
Merge remote-tracking branch 'origin/testing' into v2
This commit is contained in:
commit
697464b309
3 changed files with 62 additions and 27 deletions
|
@ -19,6 +19,8 @@
|
|||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
# 7.2.0
|
||||
upgrade=1 from_commit=738ba505f581ddd72889c889dcb34406250fea35
|
||||
# 7.3.0
|
||||
upgrade=1 from_commit=1677cb9fa9d95ab788a6acd5b310b09c7d2ab7df
|
||||
backup_restore=1
|
||||
|
@ -44,11 +46,16 @@
|
|||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
# 7.2.0
|
||||
upgrade=1 from_commit=738ba505f581ddd72889c889dcb34406250fea35
|
||||
# 7.3.0
|
||||
upgrade=1 from_commit=1677cb9fa9d95ab788a6acd5b310b09c7d2ab7df
|
||||
;;; Options
|
||||
Email=kemenaran@gmail.com
|
||||
Notification=none
|
||||
;;; Upgrade options
|
||||
; commit=00d02169435b8dc49744a1e896fe09001211d34c
|
||||
name=Testing (#396)
|
||||
; commit=738ba505f581ddd72889c889dcb34406250fea35
|
||||
name=7.2.0
|
||||
; commit=1677cb9fa9d95ab788a6acd5b310b09c7d2ab7df
|
||||
name=7.3.0
|
||||
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
mariadb-to-pg() {
|
||||
|
||||
ynh_print_info --message="Migrating to PostgreSQL database..."
|
||||
ynh_print_info --message="Migrating to PostgreSQL database..."
|
||||
|
||||
mysqlpwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||
|
||||
mysqlpwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||
|
||||
# In old instance db_user is `mmuser`
|
||||
mysql_db_user="$db_user"
|
||||
if ynh_mysql_connect_as --user="mmuser" --password="$mysqlpwd" 2> /dev/null <<< ";"; then
|
||||
|
@ -21,30 +21,32 @@ mariadb-to-pg() {
|
|||
fi
|
||||
|
||||
# Initialize PostgreSQL database
|
||||
ynh_psql_test_if_first_run
|
||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$mysqlpwd
|
||||
psqlpwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
ynh_psql_test_if_first_run
|
||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$mysqlpwd
|
||||
psqlpwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
|
||||
# Configure the new database and run Mattermost in order to create tables
|
||||
ynh_write_var_in_file --file="$install_dir/config/config.json" --key="DriverName" --value="postgres" --after="SqlSettings"
|
||||
ynh_write_var_in_file --file="$install_dir/config/config.json" --key="DataSource" --value="postgres://$db_user:$psqlpwd@localhost:5432/$db_name?sslmode=disable&connect_timeout=10" --after="SqlSettings"
|
||||
cat "$install_dir/config/config.json"
|
||||
pushd $install_dir
|
||||
ynh_write_var_in_file --file="$final_path/config/config.json" --key="DriverName" --value="postgres" --after="SqlSettings"
|
||||
ynh_write_var_in_file --file="$final_path/config/config.json" --key="DataSource" --value="postgres://$db_user:$psqlpwd@localhost:5432/$db_name?sslmode=disable&connect_timeout=10" --after="SqlSettings"
|
||||
cat "$final_path/config/config.json"
|
||||
pushd $final_path
|
||||
ynh_systemd_action --service_name="$app" --action="stop"
|
||||
set +e
|
||||
sudo -u mattermost timeout --preserve-status 30 "./bin/mattermost"
|
||||
sudo -u mattermost timeout --preserve-status 180 "./bin/mattermost"
|
||||
if [ "$?" != "0" ] && [ "$?" != "143" ] ; then
|
||||
ynh_die --message="Mattermost creation failed on Mattermost running" --ret_code=1
|
||||
ynh_die --message="Failed to run Mattermost to create PostgreSQL database tables" --ret_code=1
|
||||
fi
|
||||
set -e
|
||||
popd
|
||||
|
||||
# Some fixes to let the MariaDB -> PostgreSQL conversion working
|
||||
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_fileinfo_content_txt;' --database=mattermost
|
||||
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_posts_message_txt;' --database=mattermost
|
||||
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;" --database=mattermost
|
||||
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_fileinfo_content_txt;' --database=$db_name
|
||||
ynh_psql_execute_as_root --sql='DROP INDEX public.idx_posts_message_txt;' --database=$db_name
|
||||
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;" --database=$db_name
|
||||
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS description;" --database=$db_name
|
||||
ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS nextsyncat;" --database=$db_name
|
||||
|
||||
# Migrating from MySQL to PostgreSQL
|
||||
# Use pgloader to migrate database content from MariaDB to PostgreSQL
|
||||
tmpdir="$(mktemp -d)"
|
||||
|
||||
cat <<EOT > $tmpdir/commands.load
|
||||
|
@ -64,15 +66,21 @@ ALTER SCHEMA '$db_name' RENAME TO 'public'
|
|||
|
||||
;
|
||||
EOT
|
||||
pgloader $tmpdir/commands.load
|
||||
|
||||
# Rebuild INDEX
|
||||
ynh_psql_execute_as_root --sql='CREATE INDEX idx_fileinfo_content_txt ON public.fileinfo USING gin (to_tsvector('\''english'\''::regconfig, content))' --database=mattermost
|
||||
ynh_psql_execute_as_root --sql='CREATE INDEX idx_posts_message_txt ON public.posts USING gin (to_tsvector('\''english'\''::regconfig, (message)::text));' --database=mattermost
|
||||
|
||||
pgloader $tmpdir/commands.load
|
||||
|
||||
# Removinging MySQL database
|
||||
ynh_mysql_remove_db --db_user=$mysql_db_user --db_name=$db_name
|
||||
# Rebuild INDEX
|
||||
ynh_psql_execute_as_root --sql='CREATE INDEX idx_fileinfo_content_txt ON public.fileinfo USING gin (to_tsvector('\''english'\''::regconfig, content))' --database=$db_name
|
||||
ynh_psql_execute_as_root --sql='CREATE INDEX idx_posts_message_txt ON public.posts USING gin (to_tsvector('\''english'\''::regconfig, (message)::text));' --database=$db_name
|
||||
|
||||
|
||||
if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1
|
||||
then
|
||||
# There is a problem with version 7.3.0 and the database migration.
|
||||
# More information here: https://forum.mattermost.com/t/migrating-from-mariadb-to-postgresql-db/14194/6
|
||||
ynh_psql_execute_as_root --sql="DELETE FROM db_migrations WHERE version=92;" --database=$db_name
|
||||
fi
|
||||
# Remove the MariaDB database
|
||||
ynh_mysql_remove_db --db_user=$mysql_db_user --db_name=$db_name
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,25 @@ if mysqlshow | grep -q "^| $db_name "; then
|
|||
mariadb-to-pg
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..." --weight=10
|
||||
|
||||
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
||||
|
||||
#=================================================
|
||||
# MIGRATING DATABASE
|
||||
#=================================================
|
||||
|
||||
# Check if using MariaDB
|
||||
# This migration should be done before the upgrade
|
||||
if mysqlshow | grep -q "^| $db_name "; then
|
||||
# Mattermost only support MySQL and PostgreSQL (not MariaDB...)
|
||||
# Migrate the database from MariaDB to PostgreSQL
|
||||
mariadb-to-pg
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
|
@ -129,7 +148,8 @@ UPDATE SidebarCategories SET muted=False where muted IS NULL;
|
|||
UPDATE SidebarCategories set sorting = 'manual' where sorting='';
|
||||
UPDATE SidebarCategories set sorting = 'manual' where sorting IS NULL;
|
||||
EOM
|
||||
ynh_psql_execute_as_root --sql="$fix_old_version_sql" --database=mattermost
|
||||
|
||||
ynh_psql_execute_as_root --sql="$fix_old_version_sql" --database=$db_name
|
||||
|
||||
# Note: it's possible that some instances need other fixes
|
||||
# If nothing is displayed in the sidebar it may be needed to change the Id of SidebarCategories...
|
||||
|
|
Loading…
Add table
Reference in a new issue