Skip to content

Commit b48e6ed

Browse files
committed
fix the beforeValidate on empty environment
Signed-off-by: Qun Li <qun.li@zstack.io>
1 parent d907fa4 commit b48e6ed

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

conf/db/upgrade/beforeValidate.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
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'.
36
DELIMITER $$
47

58
DROP PROCEDURE IF EXISTS `zstack`.`update_schema_checksum` $$
69

710
CREATE PROCEDURE `zstack`.`update_schema_checksum`()
811
BEGIN
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;
1919
END $$
2020

conf/deploydb.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ if [[ `id -u` -ne 0 ]] && [[ x"$user" = x"root" ]]; then
2222
MYSQL='sudo mysql'
2323
fi
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
2630
DROP DATABASE IF EXISTS zstack;
2731
CREATE DATABASE zstack;
2832
DROP DATABASE IF EXISTS zstack_rest;
@@ -40,7 +44,14 @@ cp $base/db/V0.6__schema.sql $flyway_sql
4044
cp $base/db/upgrade/* $flyway_sql
4145

4246
url="jdbc:mysql://$host:$port/zstack"
47+
4348
bash $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+
4455
bash $flyway -user=$user -password=$password -url=$url migrate
4556

4657
eval "rm -f $flyway_sql/*"

0 commit comments

Comments
 (0)