Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 041fca2

Browse files
committed
* Generated files are now output in to a "gen" directory, that is ignored by git
* Added using a new default user (that has the account locked) for the MySQL 5.7+ integration as the DEFINER for all objects * Added a warning to the top of the generated integration file to also submit changes to the sys project * Improved the the option of skipping binary logs, so that all routines can load as well - those that used SET sql_log_bin will now select a warning when being used instead of setting the option
1 parent 039ec6f commit 041fca2

File tree

2 files changed

+54
-23
lines changed

2 files changed

+54
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gen/

generate_sql_file.sh

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
OS=`uname`
1818
SYSDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
19+
GENDIR=$SYSDIR/gen
1920
PWD=$( pwd )
2021

2122
# Grab the current sys version
22-
SYSVERSIONTMP=`cat $SYSDIR/before_setup.sql | grep sys_version | awk '{print $17}'`
23+
SYSVERSIONTMP=`cat views/version.sql | grep 'AS sys_version' | awk '{print $2}'`
2324
SYSVERSION=`echo "${SYSVERSIONTMP//\'}"`
2425

2526
MYSQLUSER="'root'@'localhost'"
@@ -54,7 +55,7 @@ Generate a MySQL 5.6 SQL file for RDS:
5455
5556
$0 -v 56 -b -u CURRENT_USER
5657
57-
Generate a MySQL 5.7 bootstrap file:
58+
Generate a MySQL 5.7 initialize / bootstrap file:
5859
5960
$0 -v 57 -m
6061
"
@@ -71,9 +72,14 @@ while getopts ":v:bhmu:" opt; do
7172
;;
7273
m)
7374
MYSQLCOMPAT=true
75+
# Bundled mysql expects the mysql.sys user to be used
76+
MYSQLUSER="'mysql.sys'@'localhost'"
7477
;;
7578
u)
76-
MYSQLUSER="${OPTARG}"
79+
if [ -z "$MYSQLCOMPAT" ] ;
80+
then
81+
MYSQLUSER="${OPTARG}"
82+
fi
7783
;;
7884
v)
7985
if [ $OPTARG == "56" ] || [ $OPTARG == "57" ] ;
@@ -105,6 +111,12 @@ then
105111
exit 1
106112
fi
107113

114+
# Create the gen directory
115+
if [[ ! -d $GENDIR ]] ;
116+
then
117+
mkdir $GENDIR
118+
fi
119+
108120
# Create output file name
109121
if [[ ! -z "$MYSQLCOMPAT" ]] ;
110122
then
@@ -117,13 +129,13 @@ fi
117129
if [[ ! -z "$MYSQLCOMPAT" ]] ;
118130
then
119131
# Pre-process all the files in a copied temp directory
120-
if [[ ! -d $SYSDIR/tmpgen ]] ;
132+
if [[ ! -d $GENDIR/tmpgen ]] ;
121133
then
122-
mkdir $SYSDIR/tmpgen
134+
mkdir $GENDIR/tmpgen
123135
fi
124-
cd $SYSDIR/tmpgen
136+
cd $GENDIR/tmpgen
125137
rm -rf *
126-
cp -r ../after_setup.sql ../tables ../triggers ../functions ../views ../procedures .
138+
cp -r $SYSDIR/after_setup.sql $SYSDIR/tables $SYSDIR/triggers $SYSDIR/functions $SYSDIR/views $SYSDIR/procedures .
127139

128140
# Switch user if requested
129141
# Remove individual copyrights
@@ -145,11 +157,26 @@ then
145157
done
146158

147159
# Start the output file from a non-removed copyright file
148-
sed -e "/sql_log_bin/d;s/'root'@'localhost'/$MYSQLUSER/g" ../before_setup.sql > $OUTPUTFILE
160+
sed -e "s/^/-- /" $SYSDIR/LICENSE > $OUTPUTFILE
161+
echo "" >> $OUTPUTFILE
162+
echo "--" >> $OUTPUTFILE
163+
echo "-- WARNING: THIS IS A GENERATED FILE, CHANGES NEED TO BE MADE ON THE UPSTREAM MYSQL-SYS REPOSITORY AS WELL" >> $OUTPUTFILE
164+
echo "-- PLEASE SUBMIT A PULL REQUEST TO https://github.com/MarkLeith/mysql-sys" >> $OUTPUTFILE
165+
echo "--" >> $OUTPUTFILE
149166
echo "" >> $OUTPUTFILE
150167

151-
# Add the files in install file order, removing new lines along the way
152-
cat "../sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | grep -v before_setup | grep -v after_setup | $SED_R 's .{8} ' | sed 's/^/./' > "./sys_$MYSQLVERSION.sql"
168+
# Add the expected user
169+
# Note this currently only works with 5.7 mysql.user structure
170+
echo "REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','','','','',0,0,0,0,'mysql_native_password',PASSWORD(UUID()),'N',CURRENT_TIMESTAMP,NULL,'Y');" >> $OUTPUTFILE
171+
echo "" >> $OUTPUTFILE
172+
echo "REPLACE INTO mysql.tables_priv VALUES ('localhost','sys','mysql.sys','sys_config','root@localhost', CURRENT_TIMESTAMP, 'Select', '');" >> $OUTPUTFILE
173+
echo "" >> $OUTPUTFILE
174+
175+
# Put in the contents of before_setup.sql, though don't collapse lines
176+
sed -e "/sql_log_bin/d;s/'root'@'localhost'/$MYSQLUSER/g;/Copyright/,/51 Franklin St/d" $SYSDIR/before_setup.sql >> $OUTPUTFILE
177+
178+
# Add the rest of the files in install file order, removing new lines along the way
179+
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | grep -v before_setup | grep -v after_setup | $SED_R 's .{8} ' | sed 's/^/./' > "./sys_$MYSQLVERSION.sql"
153180
while read file; do
154181
# First try and get a DROP command
155182
grep -E '(^DROP PROCEDURE|^DROP FUNCTION|^DROP TRIGGER)' $file >> $OUTPUTFILE
@@ -163,36 +190,39 @@ then
163190
done < "./sys_$MYSQLVERSION.sql"
164191

165192
# Does essentially nothing right now, but may in future
166-
sed -e "/sql_log_bin/d" ./after_setup.sql >> $OUTPUTFILE
193+
sed -e "/Copyright/,/51 Franklin St/d;/sql_log_bin/d" $SYSDIR/after_setup.sql >> $OUTPUTFILE
167194

168195
# Remove final leading and trailing spaces
169-
sed -i -e "s/^ *//g" $OUTPUTFILE
170-
sed -i -e "s/[ \t]*$//g" $OUTPUTFILE
196+
sed -i '' -e "s/^ *//g" $OUTPUTFILE
197+
sed -i '' -e "s/[ \t]*$//g" $OUTPUTFILE
171198
# Remove more than one empty line
172-
sed -i -e "/^$/N;/^\n$/D" $OUTPUTFILE
199+
sed -i '' -e "/^$/N;/^\n$/D" $OUTPUTFILE
173200

174-
# Move the generated file to root and clean up
175-
mv $OUTPUTFILE $SYSDIR/
176-
cd $PWD
177-
rm -rf $SYSDIR/tmpgen/
201+
mv $OUTPUTFILE $GENDIR/
202+
cd $GENDIR/
203+
rm -rf $GENDIR/tmpgen
178204
else
179-
sed -e "s/'root'@'localhost'/$MYSQLUSER/g" $SYSDIR/before_setup.sql > $SYSDIR/$OUTPUTFILE
180-
cat "./sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | $SED_R 's .{8} ' | sed 's/^/./' | grep -v before_setup | \
181-
xargs sed -e "/Copyright/,/51 Franklin St/d;s/'root'@'localhost'/$MYSQLUSER/g" >> $SYSDIR/$OUTPUTFILE
205+
sed -e "s/^/-- /" $SYSDIR/LICENSE > $GENDIR/$OUTPUTFILE
206+
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | $SED_R 's .{8} ' | sed "s/^/$(echo $SYSDIR | sed -e 's/[]\/$*.^|[]/\\&/g')/g" \
207+
| xargs sed -e "/Copyright/,/51 Franklin St/d;s/'root'@'localhost'/$MYSQLUSER/g" >> $GENDIR/$OUTPUTFILE
182208
fi
183209

184210
# Check if sql_log_bin lines should be removed
185211
if [[ ! -z "$SKIPBINLOG" ]] ;
186212
then
187-
sed -i -e "/sql_log_bin/d" $SYSDIR/$OUTPUTFILE
213+
LOGWARNING="WARNING: Using a routine that could cause binary log events, but disabling of binary logging has been removed"
214+
sed -i '' -e "s/^[ \s]*SET sql_log_bin = 0/SELECT \"$LOGWARNING\"/g" $GENDIR/$OUTPUTFILE
215+
sed -i '' -e "s/\sSET sql_log_bin = @log_bin;/SET @log_bin = NULL;/g" $GENDIR/$OUTPUTFILE
188216
SKIPBINLOG="disabled"
189217
else
190218
SKIPBINLOG="enabled"
191219
fi
192220

221+
cd $PWD
222+
193223
# Print summary
194224
echo $"
195-
Wrote file: $SYSDIR/$OUTPUTFILE
225+
Wrote file: $GENDIR/$OUTPUTFILE
196226
Object Definer: $MYSQLUSER
197227
sql_log_bin: $SKIPBINLOG
198228
"

0 commit comments

Comments
 (0)