diff options
author | Ramón M. Gómez <ramongomez@us.es> | 2020-01-17 13:50:35 +0100 |
---|---|---|
committer | Ramón M. Gómez <ramongomez@us.es> | 2020-01-17 13:50:35 +0100 |
commit | 5cb4d9b649be33c9d630d7262dd16d60e8de3b4c (patch) | |
tree | 2b6a9718a8c5683e774db3dac132d747121a6200 /installer/opengnsys_import.sh | |
parent | 9e1e247d7a49ad486e85d00314976c9d78619c04 (diff) |
#951: Script `opengnsys_import.sh` assigns a default value to non-null fields before applying database updates.
Diffstat (limited to 'installer/opengnsys_import.sh')
-rwxr-xr-x | installer/opengnsys_import.sh | 15 |
1 files changed, 15 insertions, 0 deletions
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 |