From 5cb4d9b649be33c9d630d7262dd16d60e8de3b4c Mon Sep 17 00:00:00 2001 From: "Ramón M. Gómez" Date: Fri, 17 Jan 2020 13:50:35 +0100 Subject: #951: Script `opengnsys_import.sh` assigns a default value to non-null fields before applying database updates. --- installer/opengnsys_import.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'installer') diff --git a/installer/opengnsys_import.sh b/installer/opengnsys_import.sh index 2b8ce645..4ac296d1 100755 --- a/installer/opengnsys_import.sh +++ b/installer/opengnsys_import.sh @@ -169,6 +169,21 @@ function updateSqlFile() [ $? != 0 ] && errorAndLog "${FUNCNAME}: Can't create database $AUXCATALOG" && exit 5 mysql --defaults-extra-file=$MYCNF -D "$AUXCATALOG" < $MYSQLFILE &>/dev/null [ $? != 0 ] && errorAndLog "${FUNCNAME}: Can't import $MYSQLFILE in $AUXCATALOG" && exit 5 + # Reasignar valores para campos no nulos con nulo por defecto. + mysql --defaults-extra-file=$MYCNF -D "$AUXCATALOG" -e \ + "$(mysql --defaults-extra-file=$MYCNF -Nse " +SELECT CASE WHEN DATA_TYPE LIKE '%int' THEN + CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'ALTER', COLUMN_NAME, 'SET DEFAULT 0;') + WHEN DATA_TYPE LIKE '%char' THEN + CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'ALTER', COLUMN_NAME, 'SET DEFAULT \'\';') + WHEN DATA_TYPE = 'text' THEN + CONCAT_WS(' ', 'ALTER TABLE', TABLE_NAME, 'MODIFY', COLUMN_NAME, 'TEXT NOT NULL;') + END + FROM information_schema.columns + WHERE TABLE_SCHEMA='$AUXCATALOG' + AND IS_NULLABLE='NO' + AND COLUMN_DEFAULT IS NULL + AND COLUMN_KEY='';")" for file in $FILES; do importSqlFile $DBDIR/$file -- cgit v1.2.3-18-g5258