mirror of
https://github.com/YunoHost-Apps/hubzilla_ynh.git
synced 2024-09-03 19:26:21 +02:00
Different approach for db migration
This commit is contained in:
parent
0095d3750a
commit
b0e957cce8
2 changed files with 42 additions and 14 deletions
|
@ -9,6 +9,42 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
# PERSONAL HELPERS
|
# 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
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
|
||||||
|
;
|
||||||
|
EOT
|
||||||
|
pgloader $tmpdir/commands.load
|
||||||
|
|
||||||
|
# Remove the MariaDB database
|
||||||
|
ynh_mysql_remove_db --db_user=$mysql_db_user --db_name=$db_name
|
||||||
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
|
|
|
@ -57,20 +57,12 @@ fi
|
||||||
# MIGRATING DATABASE
|
# MIGRATING DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if mysqlshow | grep -q "^| $db_name "; then
|
# Check if using MariaDB
|
||||||
|
# This migration should be done before the upgrade
|
||||||
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=10
|
if mysqlshow | grep -q "^| $db_name "; then
|
||||||
|
# Migrate the database from MySQL/MariaDB to PostgreSQL
|
||||||
postgresql_db_pwd=$(ynh_string_random --length=24)
|
remove_psql_in_case_of_error=1
|
||||||
ynh_app_setting_set --app=$app --key=postgresql_db_pwd --value=$postgresql_db_pwd
|
mariadb-to-pg
|
||||||
ynh_psql_test_if_first_run
|
|
||||||
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$postgresql_db_pwd
|
|
||||||
# Migrating from MySQL to PostgreSQL
|
|
||||||
pgloader mysql://$db_user:$db_pwd@localhost:3306/$db_name postgresql://$db_user:$postgresql_db_pwd@localhost:5432/$db_name
|
|
||||||
# Removinging MySQL database
|
|
||||||
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
|
|
||||||
else
|
|
||||||
ynh_print_info --message="No migration needed"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue