diff options
author | Ramón M. Gómez <ramongomez@us.es> | 2020-01-27 11:39:47 +0100 |
---|---|---|
committer | Ramón M. Gómez <ramongomez@us.es> | 2020-01-27 11:46:55 +0100 |
commit | 785085ba803aa9abfb68afd54731f5634959fe44 (patch) | |
tree | eb83cdda117181334ae5b76cf9de56ca064b2783 /installer/opengnsys_update.sh | |
parent | 45e3244cd69944ddf4246996539dacd1caa14bd9 (diff) |
#951: Set default value to non-null pending fields when updating the database (thanks to `acodoner` for reporting this problem on topic:418).
Diffstat (limited to 'installer/opengnsys_update.sh')
-rwxr-xr-x | installer/opengnsys_update.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/installer/opengnsys_update.sh b/installer/opengnsys_update.sh index bb0353d5..f249d62f 100755 --- a/installer/opengnsys_update.sh +++ b/installer/opengnsys_update.sh @@ -365,6 +365,22 @@ function importSqlFile() user=$dbuser password=$dbpassword EOT + # Antes de actualizar, reasignar valores para campos no nulos con nulo por defecto. + mysql --defaults-extra-file=$MYCNF -D "$database" -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;') + ELSE '' + END + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA='$database' + AND IS_NULLABLE='NO' + AND COLUMN_DEFAULT IS NULL + AND COLUMN_KEY='';")" # Ejecutar actualización y borrar fichero de credenciales. mysql --defaults-extra-file=$mycnf --default-character-set=utf8 -D "$database" < $tmpfile status=$? |