Skip to content
Permalink
Browse files

Migrate schema from db to public in mysql migration script

[ci skip]
  • Loading branch information
oliverguenther committed Feb 5, 2020
1 parent 86c8994 commit 6ff2bd4541c494e7f9c4aa693c4ceafd134189f8
Showing with 27 additions and 2 deletions.
  1. +27 −2 script/migration/migrate-from-pre-8.sh
@@ -36,7 +36,7 @@ POSTGRES_PORT=5439
MYSQL_PORT=3305 # has to be free on localhost
MYSQL_USER=root
export MYSQL_PWD=root # export to be used by mysql client
DATABASE=fitopenproject
DATABASE=openproject

SKIP_STEP_1=false
MIGRATION_TIMEOUT_S=600 # wait at most 10 minutes for the migration from 8 to 10 to finish
@@ -197,7 +197,32 @@ else
fi

echo
echo "2.3) Dumping migrated database to $DATABASE-migrated.sql"
echo "2.3) Renaming PostgreSQL schema from $DATABASE to public"

MOVE_SCHEMA_FN='' read -r -d '' String <<"EOF"
CREATE OR REPLACE FUNCTION move_schema_to_public(old_schema varchar) RETURNS void LANGUAGE plpgsql VOLATILE AS
$$
DECLARE
row record;
BEGIN
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = quote_ident(old_schema)
LOOP
EXECUTE 'ALTER TABLE ' || quote_ident(old_schema) || '.' || quote_ident(row.tablename) || ' SET SCHEMA public;';
END LOOP;
END;
$$;
EOF


docker exec -e PGPASSWORD=postgres -it migrate8to10 psql \
-h $DOCKER_HOST_IP \
-p $POSTGRES_PORT \
-U postgres \
-d $DATABASE \
-c "${MOVE_SCHEMA_FN}; SELECT * FROM move_schema_to_public('$DATABASE');"

echo
echo "2.4) Dumping migrated database to $DATABASE-migrated.sql"

# using the running docker image to dump the database to ensure we use the same
# postgres client version and also so that a postgres client is not necessary to run this script

0 comments on commit 6ff2bd4

Please sign in to comment.
You can’t perform that action at this time.