Created
July 18, 2018 22:02
-
-
Save jasonsnider/3e2295cebfc8f0f7b4f848c1b06368ac to your computer and use it in GitHub Desktop.
Change all varchar(36) to a char(36) - Assists with the migration from CakePHP v2 - v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DB_HOST='localhost' | |
DB_USER='root' | |
DB_PASS='password' | |
DB='default' | |
functionAlterTable(){ | |
read a b c <<< "${ROW}" | |
echo "START QUERY: alter table $a modify $b char(36);" | |
mysql -h $DB_HOST -u $DB_USER --password="$DB_PASS" $DB -e "alter table $a modify $b char(36);" | |
echo "END QUERY: alter table $a modify $b char(36);" | |
echo '-------------------'; | |
} | |
mysql -h $DB_HOST -u $DB_USER --password="$DB_PASS" $DB -e "SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='$DB' AND COLUMN_TYPE='varchar(36)'" | while read RESULTS; | |
do | |
CNT=${#RESULTS[@]} | |
for ((i=0 ; i<${CNT}; i++)) | |
do | |
ROW=${RESULTS[$i]} | |
functionAlterTable | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment