File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11-- Update `schema_version' since we've changed SQL to match the expectation
22-- of the newer version MariaDB.
3+ --
4+ -- WARNING: `schema_version' table doesn't exist on a clean environment, thus
5+ -- after 'flyway clean' we prepared an empty table after 'flyway baseline'.
36DELIMITER $$
47
58DROP PROCEDURE IF EXISTS ` zstack` .` update_schema_checksum` $$
69
710CREATE PROCEDURE ` zstack` .` update_schema_checksum` ()
811BEGIN
9- IF EXISTS(SELECT schema_name FROM information_schema .schemata WHERE schema_name = ' zstack ' )
12+ IF EXISTS(SELECT table_name FROM information_schema .tables WHERE table_name = ' schema_version ' )
1013 THEN
11- IF EXISTS(SELECT table_name FROM information_schema .tables WHERE table_name = ' schema_version' )
12- THEN
13- update ` zstack` .` schema_version` set ` checksum` = 1083194846 where ` script` = ' V1.6__schema.sql' and ` checksum` <> 1083194846 ;
14- update ` zstack` .` schema_version` set ` checksum` = - 1569422253 where ` script` = ' V2.1.0__schema.sql' and ` checksum` <> - 1569422253 ;
15- update ` zstack` .` schema_version` set ` checksum` = 1564279419 where ` script` = ' V3.0.0__schema.sql' and ` checksum` <> 1564279419 ;
16- update ` zstack` .` schema_version` set ` checksum` = 565652311 where ` script` = ' V3.7.2__schema.sql' and ` checksum` <> 565652311 ;
17- END IF;
14+ update ` zstack` .` schema_version` set ` checksum` = 1083194846 where ` script` = ' V1.6__schema.sql' and ` checksum` <> 1083194846 ;
15+ update ` zstack` .` schema_version` set ` checksum` = - 1569422253 where ` script` = ' V2.1.0__schema.sql' and ` checksum` <> - 1569422253 ;
16+ update ` zstack` .` schema_version` set ` checksum` = 1564279419 where ` script` = ' V3.0.0__schema.sql' and ` checksum` <> 1564279419 ;
17+ update ` zstack` .` schema_version` set ` checksum` = 565652311 where ` script` = ' V3.7.2__schema.sql' and ` checksum` <> 565652311 ;
1818 END IF;
1919END $$
2020
Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ if [[ `id -u` -ne 0 ]] && [[ x"$user" = x"root" ]]; then
2222 MYSQL=' sudo mysql'
2323fi
2424
25- $MYSQL --user=$user --password=$password --host=$host --port=$port << EOF
25+ mysql_run () {
26+ $MYSQL --user=$user --password=$password --host=$host --port=$port " $@ "
27+ }
28+
29+ mysql_run << EOF
2630DROP DATABASE IF EXISTS zstack;
2731CREATE DATABASE zstack;
2832DROP DATABASE IF EXISTS zstack_rest;
@@ -40,7 +44,14 @@ cp $base/db/V0.6__schema.sql $flyway_sql
4044cp $base /db/upgrade/* $flyway_sql
4145
4246url=" jdbc:mysql://$host :$port /zstack"
47+
4348bash $flyway -user=$user -password=$password -url=$url clean
49+
50+ # create baseline and clean its contents for 'beforeValidate.sql'
51+ mysql_run -se " SELECT table_name FROM information_schema.tables WHERE table_name = 'schema_version'" | \
52+ grep -wq schema_version || \
53+ ( bash $flyway -user=$user -password=$password -url=$url baseline; mysql_run zstack -e " DELETE FROM schema_version" )
54+
4455bash $flyway -user=$user -password=$password -url=$url migrate
4556
4657eval " rm -f $flyway_sql /*"
You can’t perform that action at this time.
0 commit comments