summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2020-01-17 13:50:35 +0100
committerRamón M. Gómez <ramongomez@us.es>2020-01-17 13:50:35 +0100
commit5cb4d9b649be33c9d630d7262dd16d60e8de3b4c (patch)
tree2b6a9718a8c5683e774db3dac132d747121a6200
parent9e1e247d7a49ad486e85d00314976c9d78619c04 (diff)
#951: Script `opengnsys_import.sh` assigns a default value to non-null fields before applying database updates.
-rw-r--r--admin/Database/ogAdmBD-1.1.1-1.1.1a.sql7
-rwxr-xr-xinstaller/opengnsys_import.sh15
2 files changed, 15 insertions, 7 deletions
diff --git a/admin/Database/ogAdmBD-1.1.1-1.1.1a.sql b/admin/Database/ogAdmBD-1.1.1-1.1.1a.sql
deleted file mode 100644
index cca72327..00000000
--- a/admin/Database/ogAdmBD-1.1.1-1.1.1a.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-### Fichero de actualización de la base de datos.
-# OpenGnsys 1.1.1 - OpenGnsys 1.1.1a
-#use ogAdmBD
-
-# Evitar fallo al obtener configuración de ordenador.
-ALTER TABLE ordenadores_particiones
- ALTER idperfilsoft SET DEFAULT 0;
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