1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
mattermost_ynh/scripts/_common.sh
eric_G 0f5db1d1d9
Testing (#435)
* scripts: reduce pgloader's prefetched columns 

This helps fixing stack overflow errors on large
databases.

* scripts: increase the migration timeout again

It seems to be too short on some lesser-powered VMs.

* Update manifest.json

* Auto-update README

* [autopatch] Fix Host and X-Forwarded-For header spoofing

* conf: upgrade to Mattermost ESR 8.1.1 (#431)

https://docs.mattermost.com/install/self-managed-changelog.html#release-v8-1-extended-support-release

* Packaging format v2 (#406)

* backup script for PostgreSQL (#376)

Inspired from https://github.com/YunoHost-Apps/moodle_ynh/blob/master/scripts/backup

* Adapt to PostgreSQL (#375)

Question: in https://docs.mattermost.com/install/install-debian.html#install-postgresql-database-server, I see `BindsTo=postgresql.service` while in the original file here I find `Requires=mysql.service`. I don't know which one makes sense, so I keep the orinigal Yunohost version (Requires)

* config.json for PostgreSQL (#374)

Inspired from the original MySQL config.json and from Mattermost documentation https://docs.mattermost.com/install/install-debian.html#install-postgresql-database-server

* Install with PostgreSQL (#373)

I took inspiration from https://github.com/YunoHost-Apps/commento_ynh/blob/master/scripts/install

* install postgresql

* Reordering

* reset config file

* Update _common.sh

* Update config.json

* Fix

* Migration (#382)

* add migration

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Fix

* Fix

* Fix

* Update install

* Update upgrade

* Fix

* Update install

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update install

* Fix

* Fix

* Fix

* Update upgrade

* Cleaning up

* Update upgrade

* Update _common.sh

* Update check_process

* Update _common.sh

* Fix

* Update mysql-to-pg.conf

* Update upgrade

* Update systemd.service

* Cleaning

* Update _common.sh

* Fix

* Update upgrade

* Update _common.sh

* Update upgrade

* Update backup

* Fix

* Fix

* Update upgrade

* Update upgrade

* Update systemd.service

* Update _common.sh

* Revert "Update _common.sh"

This reverts commit d880150af9.

* Cleaning

* Fix

* Update check_process

* Fix

* Update _common.sh

* Fix

* Update _common.sh

* Fix

* Update manifest.json

* Update install

* Update _common.sh

* Update upgrade

* Fix

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Update _common.sh

* Auto-update README

* Update _common.sh

* Upgrade to v7.4.0

* Auto-update README

* Upgrade to v7.5.2

* Auto-update README

* Update config.json

* [fix] mariadb to postgres migration

* Auto-update README

* [fix] Update manifest requirements

* Update manifest.json

* Update config.json

* upgrade config to upstream

* Fix linter

* Update _common.sh

* v2

* Fix

* Auto-update README

* Fix

* Auto-update README

* Update upgrade

* Fix

* Cleaning

* add apt

* Auto-update README

* cleaning

* fix data path var

* fix

* Auto-update README

* Update backup

* add more apt

* Update manifest.toml

* Update tests.toml

* Fix

* Update _common.sh

* Update upgrade

* Update restore

* Update remove

* cleaning

* Update install

* Update upgrade

* Update upgrade

* Update upgrade

* Update upgrade

* Update manifest.toml

* 7.7.1

* Update manifest.json

* Auto-update README

* Update config.json

* Auto-update README

* cleaning

* Auto-update README

* Update ADMIN.md

* Update ADMIN_fr.md

* fix

* Delete check_process

* 7.8.1

* Auto-update README

* Auto-update README

* Update manifest.toml

* Auto-update README

* fix migration from 7.3.0

* Update manifest.toml

* fix migration from 7.3.0

* cleaning

* Update manifest.toml

* src

* Update upgrade

* Update upgrade

* Update tests.toml

* remove src

* 7.9.1

* Auto-update README

* Update config.json

* Update doc/DESCRIPTION.md

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Auto-update README

* Update tests.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update manifest.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update manifest.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update upgrade

* Update install

* Update DESCRIPTION_fr.md

* Auto-update README

* Update _common.sh

* Update manifest.toml

* Update manifest.toml

* Auto-update README

* Update manifest.toml

* Update upgrade

* Update manifest.toml

* Auto-update README

* cleaning

* Auto-update README

* Update nginx.conf

* Update manifest.toml

* Auto-update README

* cleaning

* Update doc/ADMIN.md

Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>

* Update doc/ADMIN_fr.md

Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>

* 8.0.0

* Auto-update README

* Update manifest.toml

* Auto-update README

* 8.1.0

* Auto-update README

* Update upgrade

* Update tests.toml

* Update tests.toml

* Update _common.sh

* Update manifest.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update manifest.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update manifest.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update tests.toml

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>

* Update manifest.toml

* DEBUG: see if other migrations pass (#430)

* Update manifest.toml

* Auto-update README

* Revert "DEBUG: see if other migrations pass (#430)"

This reverts commit 8532bd3ba2.

* Update tests.toml

* scripts: fix MySQL migration

The PostgreSQL database has already been created,
no need to create it manually.

* scripts: improve DB migration comment

* Update config.json

* Update tests.toml

* Fix v2 database deletion on error (#434)

* scripts: improve comments

* scripts: manually remove MariaDB database if needed

---------

Co-authored-by: biva <biva@users.noreply.github.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>
Co-authored-by: yunohost-bot <yunohost-bot@users.noreply.github.com>
Co-authored-by: ljf <ljf+git@grimaud.me>
Co-authored-by: Kay0u <pierre@kayou.io>
Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>
Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>

* Update manifest.toml

* Auto-update README

* Update manifest.toml

* Auto-update README

---------

Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>
Co-authored-by: tituspijean <titus+yunohost@pijean.ovh>
Co-authored-by: biva <biva@users.noreply.github.com>
Co-authored-by: yunohost-bot <yunohost-bot@users.noreply.github.com>
Co-authored-by: ljf <ljf+git@grimaud.me>
Co-authored-by: Kay0u <pierre@kayou.io>
Co-authored-by: Alexandre Aubin <alex.aubin@mailoo.org>
2023-09-11 21:36:20 +02:00

99 lines
4.4 KiB
Bash

#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
#=================================================
mariadb-to-pg() {
ynh_print_info --message="Migrating to PostgreSQL database..."
# Retrieve MySQL user and password
mysqlpwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
mysql_db_user="$db_user"
if ynh_mysql_connect_as --user="mmuser" --password="$mysqlpwd" 2> /dev/null <<< ";"; then
# On old instances db_user is `mmuser`
mysql_db_user="mmuser"
fi
# 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
ynh_systemd_action --service_name="$app" --action="stop"
set +e
sudo -u $app timeout --preserve-status 300 "./bin/mattermost"
if [ "$?" != "0" ] && [ "$?" != "143" ] ; then
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=$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
# Focalboard is broken in Mattermost 7.3.0
if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1
then
remove_focalboard_if_7_3_0="EXCLUDING TABLE NAMES MATCHING ~/^focalboard_/"
else
remove_focalboard_if_7_3_0=""
fi
# 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
INTO postgresql://$db_user:$db_pwd@127.0.0.1:5432/$db_name
WITH include no drop, truncate, create no tables,
create no indexes, preserve index names, no foreign keys,
data only, workers = 16, concurrency = 1, prefetch rows = 10000
SET MySQL PARAMETERS
net_read_timeout = '90',
net_write_timeout = '180'
$remove_focalboard_if_7_3_0
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=$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
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================