From 785085ba803aa9abfb68afd54731f5634959fe44 Mon Sep 17 00:00:00 2001 From: "Ramón M. Gómez" Date: Mon, 27 Jan 2020 11:39:47 +0100 Subject: #951: Set default value to non-null pending fields when updating the database (thanks to `acodoner` for reporting this problem on topic:418). --- installer/opengnsys_update.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'installer') 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=$? -- cgit v1.2.3-18-g5258