Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 'user' -> 'users' migration script for mysql databases #647

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ dependencies {
compile "org.grails.plugins:mail:2.0.0.RC4"
compile "org.grails.plugins:grails-spring-websocket:2.3.0"
compile group: 'eu.bitwalker', name: 'UserAgentUtils', version: '1.20'
runtime 'mysql:mysql-connector-java:5.1.36'
runtime 'mysql:mysql-connector-java:8.0.12'
// runtime for postgresql works fine
// but compile group kept for testing as per closed pull request #368
//compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
//runtime 'org.postgresql:postgresql:42.2.5'
// as per instructions @ https://github.com/kaleidos/grails-postgresql-extensions/blob/master/README.md
// streama seems to work fine without it though
//compile 'org.grails.plugins:postgresql-extensions:6.1.0'

}

task wrapper(type: Wrapper) {
Expand Down
38 changes: 38 additions & 0 deletions migration-scripts/mysql-table-user-to-users.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

# get streama database user name, password and DB name for mysql
echo input mysql user name for streama database:
read -s USER
echo ''
echo input mysql user password for streama database:
read -s PASS
echo ''
echo input mysql database name for streama database:
read -s DB
echo ''

# check for 'user'/'users' table
if [ -z "$(mysql -u $USER --password=$PASS -D $DB -e "show tables like 'user'")" ]; then
echo "'user' table does not exist"
if [ -z "$(mysql -u $USER --password=$PASS -D $DB -e "show tables like 'users'")" ]; then
echo "'users' table does not exist either"
echo "there is an issue with your streama database"
else
echo "'users table exists'"
echo "no need to rename table"
fi

else
echo "'user' table exists"
echo "renaming 'user' table to 'users'"
mysql -u $USER --password=$PASS -D $DB -e "ALTER TABLE user RENAME users"
if [ -z "$(mysql -u $USER --password=$PASS -D $DB -e "show tables like 'users'")" ]; then
echo "rename failed"
else
echo "rename succeeded"
fi

fi

echo ""
echo "finished"