Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Memorekall Member New
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rekall
Memorekall Member New
Commits
b83dfbfd
Verified
Commit
b83dfbfd
authored
3 years ago
by
David Beniamine
Browse files
Options
Downloads
Patches
Plain Diff
WIP add data migration script
parent
4539ba97
No related branches found
No related tags found
1 merge request
!46
Tuleap 88 db migration
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/migrations/migrate_from_symfony_3_to_5.sh
+58
-0
58 additions, 0 deletions
tools/migrations/migrate_from_symfony_3_to_5.sh
with
58 additions
and
0 deletions
tools/migrations/migrate_from_symfony_3_to_5.sh
0 → 100755
+
58
−
0
View file @
b83dfbfd
#!/bin/bash
BASE_DIR
=
$(
realpath
"
$(
dirname
$0
)
/../.."
)
source
$BASE_DIR
/.env
BACKUP_DB
=
"
${
MYSQL_DATABASE
}
_BACKUP_3_TO_5"
mysql_cmd
=
"docker-compose exec mysql mysql -u root -p
$MYSQL_ROOT_PASSWORD
"
#
# Step 1 backup the db
#
$mysql_cmd
-e
"use
$BACKUP_DB
"
backup
=
$?
if
[
"
$backup
"
-ne
0
]
;
then
echo
"Backup DB does not exists, saving the current DB"
# The backup db does not exists
echo
"Creating DB
$BACKUP_DB
"
$mysql_cmd
-e
"CREATE DATABASE
$BACKUP_DB
"
echo
"Saving
$MYSQL_DATABASE
to
$BACKUP_DB
"
docker-compose
exec
mysql mysqldump
-u
root
-p
$MYSQL_ROOT_PASSWORD
$MYSQL_DATABASE
|
\
grep
-v
Warning |
docker
exec
-i
$(
docker-compose ps
-q
mysql
)
mysql
-u
root
-p
$MYSQL_ROOT_PASSWORD
$BACKUP_DB
echo
"Backup done"
else
echo
"A previous backup exists, skipping backup step"
fi
#
# Step 2 Reload db with initial data
#
docker-compose
exec
memorekall-member composer reload-db
#
# Step 3 remove artifact data and copy data from backup table
#
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"
TABLES
=
"user reset_password_request capsule capsuleGroup capsules_groups doctrine_migration_versions editeur_capsule invitation_editeur_capsule"
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"
done
echo
"All done"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment