Skip to content
Snippets Groups Projects
Verified Commit 62d491bc authored by David Beniamine's avatar David Beniamine
Browse files

Migration script from symfony 3 to 5

parent b83dfbfd
Branches
Tags
1 merge request!46Tuleap 88 db migration
......@@ -33,26 +33,36 @@ fi
docker-compose exec memorekall-member composer reload-db
#
# Step 3 remove artifact data and copy data from backup table
# Step 3 empty the newly generated database and recopy data from the backup
#
echo "Droping fixture capsule"
$mysql_cmd $MYSQL_DATABASE -e "delete from capsule"
echo "Done"
echo "Droping fixture users"
$mysql_cmd $MYSQL_DATABASE -e "delete from user"
echo "Done"
# Columns renaming in the form pattern/replacement/sedopts
declare -A COLUMNS_REPLACEMENTS
COLUMNS_REPLACEMENTS[user]='credential_expired/credentials_expired as credential_expired/'
# Old capsule table does not have a password field
COLUMNS_REPLACEMENTS[capsule]='password/NULL as password/'
TABLES="user reset_password_request capsule capsuleGroup capsules_groups doctrine_migration_versions editeur_capsule invitation_editeur_capsule"
TABLES="user reset_password_request capsule doctrine_migration_versions editeur_capsule"
echo "SET foreign_key_checks = 0;" > $$.sql
for table in $TABLES; do
echo "Reloading table $table"
COLUMNS=$($mysql_cmd --batch --disable-column-names \
-e "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$table' AND TABLE_SCHEMA='$MYSQL_DATABASE'" |\
grep -v "Warning" | tr '\r\n' ', ' | sed 's/, $//'
)
#echo $COLUMNS
# TODO : what should we do about columns with name mismatch ex user.credential_expired ?
$mysql_cmd -e "INSERT INTO $MYSQL_DATABASE.$table SELECT $COLUMNS FROM $BACKUP_DB.$table;"
echo "done"
if [ ! -z "${COLUMNS_REPLACEMENTS[$table]}" ]; then
COLUMNS_OLD=$(echo $COLUMNS | sed "s/${COLUMNS_REPLACEMENTS[$table]}")
else
COLUMNS_OLD=$COLUMNS
fi
echo "DELETE FROM $MYSQL_DATABASE.$table;" >> $$.sql
echo "INSERT INTO $MYSQL_DATABASE.$table ($COLUMNS) SELECT $COLUMNS_OLD FROM $BACKUP_DB.$table;" >> $$.sql
done
echo "SET foreign_key_checks = 1;" >> $$.sql
cat $$.sql | docker exec -i $(docker-compose ps -q mysql) mysql -u root -p$MYSQL_ROOT_PASSWORD
echo "All done"
rm $$.sql
#
# Step 4 Ensure entity are stored in JSON format and not array
#
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment