2021-01-11 23:46:48 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
2024-06-22 21:41:44 +02:00
|
|
|
# COMMON VARIABLES AND CUSTOM HELPERS
|
2021-01-11 23:46:48 +01:00
|
|
|
#=================================================
|
|
|
|
|
2023-11-09 20:01:57 +01:00
|
|
|
# We want Mattermost emails to be sent from the main domain
|
|
|
|
# (the one for which the emails headers are properly configured),
|
|
|
|
# and not the subdomain or secondary domain used for Mattermost.
|
|
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
|
|
|
2023-03-06 22:26:35 +01:00
|
|
|
mariadb-to-pg() {
|
|
|
|
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_print_info "Migrating to PostgreSQL database..."
|
2023-03-06 22:26:35 +01:00
|
|
|
|
2023-09-11 21:36:20 +02:00
|
|
|
# Retrieve MySQL user and password
|
2024-06-22 21:41:44 +02:00
|
|
|
mysqlpwd=$(ynh_app_setting_get --key=mysqlpwd)
|
2023-03-06 22:26:35 +01:00
|
|
|
|
|
|
|
mysql_db_user="$db_user"
|
2024-06-22 21:41:44 +02:00
|
|
|
if ynh_mysql_db_shell <<< ";"; then
|
2023-09-11 21:36:20 +02:00
|
|
|
# On old instances db_user is `mmuser`
|
2023-03-06 22:26:35 +01:00
|
|
|
mysql_db_user="mmuser"
|
|
|
|
fi
|
|
|
|
|
2023-09-11 21:36:20 +02:00
|
|
|
# The PostgreSQL database has already been created by Yunohost before running the script.
|
|
|
|
# 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:$db_pwd@localhost:5432/$db_name?sslmode=disable&connect_timeout=10" --after="SqlSettings"
|
|
|
|
cat "$install_dir/config/config.json"
|
|
|
|
pushd $install_dir
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_systemctl --service="$app" --action="stop"
|
2023-03-06 22:26:35 +01:00
|
|
|
set +e
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_exec_as_app timeout --preserve-status 300 "./bin/mattermost"
|
2023-03-06 22:26:35 +01:00
|
|
|
if [ "$?" != "0" ] && [ "$?" != "143" ] ; then
|
2024-06-22 21:41:44 +02:00
|
|
|
ynh_die "Failed to run Mattermost to create PostgreSQL database tables" --ret_code=1
|
2023-03-06 22:26:35 +01:00
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
popd
|
|
|
|
|
|
|
|
# Some fixes to let the MariaDB -> PostgreSQL conversion working
|
2024-06-23 16:48:37 +02:00
|
|
|
ynh_psql_db_shell <<< 'DROP INDEX public.idx_fileinfo_content_txt;'
|
2024-06-22 21:41:44 +02:00
|
|
|
|
2024-06-23 16:48:37 +02:00
|
|
|
ynh_psql_db_shell <<< 'DROP INDEX public.idx_posts_message_txt;'
|
2024-06-22 21:41:44 +02:00
|
|
|
|
|
|
|
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;"
|
|
|
|
|
|
|
|
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS description;"
|
|
|
|
|
|
|
|
ynh_mysql_db_shell <<< "ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS nextsyncat;"
|
|
|
|
|
2023-03-07 11:42:53 +01:00
|
|
|
# Focalboard is broken in Mattermost 7.3.0
|
|
|
|
if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1
|
|
|
|
then
|
2023-03-17 22:46:56 +01:00
|
|
|
remove_focalboard_if_7_3_0="EXCLUDING TABLE NAMES MATCHING ~/^focalboard_/"
|
|
|
|
else
|
|
|
|
remove_focalboard_if_7_3_0=""
|
2023-03-07 11:42:53 +01:00
|
|
|
fi
|
2023-03-06 22:26:35 +01:00
|
|
|
|
|
|
|
# Use pgloader to migrate database content from MariaDB to PostgreSQL
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
|
|
|
|
cat <<EOT > $tmpdir/commands.load
|
|
|
|
LOAD DATABASE
|
|
|
|
FROM mysql://$mysql_db_user:$mysqlpwd@127.0.0.1:3306/$db_name
|
2023-09-11 21:36:20 +02:00
|
|
|
INTO postgresql://$db_user:$db_pwd@127.0.0.1:5432/$db_name
|
2023-03-06 22:26:35 +01:00
|
|
|
|
|
|
|
WITH include no drop, truncate, create no tables,
|
|
|
|
create no indexes, preserve index names, no foreign keys,
|
2023-07-28 08:33:53 +02:00
|
|
|
data only, workers = 16, concurrency = 1, prefetch rows = 10000
|
2023-03-06 22:26:35 +01:00
|
|
|
|
|
|
|
SET MySQL PARAMETERS
|
|
|
|
net_read_timeout = '90',
|
|
|
|
net_write_timeout = '180'
|
|
|
|
|
2023-03-17 22:46:56 +01:00
|
|
|
$remove_focalboard_if_7_3_0
|
|
|
|
|
2023-03-06 22:26:35 +01:00
|
|
|
ALTER SCHEMA '$db_name' RENAME TO 'public'
|
|
|
|
|
|
|
|
;
|
|
|
|
EOT
|
|
|
|
pgloader $tmpdir/commands.load
|
|
|
|
|
|
|
|
# Rebuild INDEX
|
2024-06-23 16:48:37 +02:00
|
|
|
ynh_psql_db_shell <<< 'CREATE INDEX idx_fileinfo_content_txt ON public.fileinfo USING gin (to_tsvector('\''english'\''::regconfig, content))'
|
2024-06-22 21:41:44 +02:00
|
|
|
|
2024-06-23 16:48:37 +02:00
|
|
|
ynh_psql_db_shell <<< 'CREATE INDEX idx_posts_message_txt ON public.posts USING gin (to_tsvector('\''english'\''::regconfig, (message)::text));'
|
2023-03-06 22:26:35 +01:00
|
|
|
|
|
|
|
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
|
2024-06-23 16:48:37 +02:00
|
|
|
ynh_psql_db_shell <<< "DELETE FROM db_migrations WHERE version=92;"
|
2024-06-22 21:41:44 +02:00
|
|
|
|
2023-03-06 22:26:35 +01:00
|
|
|
fi
|
2023-09-11 21:36:20 +02:00
|
|
|
|
2023-03-06 22:26:35 +01:00
|
|
|
# Remove the MariaDB database
|
2024-06-22 21:41:44 +02:00
|
|
|
# FIXME ynh_mysql_drop_db && ynh_mysql_drop_user --db_user=$mysql_db_user --db_name=$db_name
|
2023-03-06 22:26:35 +01:00
|
|
|
}
|