Bug 10517: Use `DROP USER IF EXISTS` and remove ` || true`.
authorRudolf Byker <rudolfbyker@gmail.com>
Wed, 8 Jan 2020 09:20:02 +0000 (11:20 +0200)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 3 May 2022 21:19:50 +0000 (11:19 -1000)
commite6a40fc9ed4e82370ae92b394823a3d07b1bb130
tree84dab91d0e99282585b019187a8addcaf7c36692
parentbf1ebfc0929085930bda8bbb0c16b8ea51b9e32f
Bug 10517: Use `DROP USER IF EXISTS` and remove ` || true`.

When restoring a Koha instance, and the database user does not exist, an error is shown,
although it is prevented from stopping the script by ` || true`. This patch removes the
` || true` guard, and rather uses `DROP USER IF EXISTS` which does exactly what one
would expect, without confusing error messages, whether the user existed or not.

To test:
1) Assume your Koha instance is called `asdf`.
1) Export the Koha instance using `koha-dump`.
2) Remove the instance completely using `koha-remove`.
3) Import it again using `koha-restore`.
4) No error should be shown, and the import should work. There was NO user to drop, therefore `DROP USER IF EXISTS` did nothing.
5) A database user called `koha_asdf` should exist, and have all privileges on the database of the same name.
6) Remove the instance again using `koha-remove`.
7) Now create a database user in MySQL called `koha_instance` where instance is the name of your dumped koha instance.
8) Import your koha instance again using `koha-restore`.
9) Again, no error should be shown, and the import should work. There WAS a user to drop, therefore `DROP USER IF EXISTS` dropped the user before creating a new one.
10) Again, a database user called `koha_asdf` should exist, and have all privileges on the database of the same name.

Sponsored-by: Reformational Study Centre
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
debian/scripts/koha-restore