Bug 14533

Summary: koha-create --use-db option shouldn't create any db or db user
Product: Koha Reporter: Tomás Cohen Arazi <tomascohen>
Component: Command-line UtilitiesAssignee: Mark Tompsett <mtompset>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, mtompset, nick, robin, yarikdot
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=9409
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 18877    
Attachments: Patch - remove CREATE USER when koha-create --use-db
Bug 14533: remove CREATE USER when koha-create --use-db
Bug 14533: Deal with comment #2
Bug 14533: Deal with comment #2
Bug 14533: remove CREATE USER when koha-create --use-db
Bug 14533: Deal with comment #2
Bug 14533: remove CREATE USER when koha-create --use-db
Bug 14533: Make --use-db display a message if no DB defined

Description Tomás Cohen Arazi 2015-07-14 14:44:59 UTC
It is counter-intuitive to have an option switch --use-db which tries to create a db (what is --create-db for then?) and also a db user... It is of more use to just pass it the data for using an already created db with its credentials.
Comment 1 Yarik Dot 2015-08-06 23:29:52 UTC
Created attachment 41424 [details] [review]
Patch - remove CREATE USER when koha-create --use-db

Please, check the attachment.
Comment 2 Tomás Cohen Arazi 2015-08-07 14:41:45 UTC
(In reply to Yarik Dot from comment #1)
> Created attachment 41424 [details] [review] [review]
> Patch - remove CREATE USER when koha-create --use-db
> 
> Please, check the attachment.

I think the behaviour should be:

- If the user passes DB parameters (user, pass, hostname, dbname), use them to configure the instance. This needs more parameters to be added to koha-create. hostname should default to 'localhost' if ommited.
- If some of the new parameters is missing, fallback to what is configured in /etc/koha/passwd.
- If some of the relevant parameters is missing, fail loudly.
Comment 3 Tomás Cohen Arazi 2015-08-07 14:43:43 UTC
Comment on attachment 41424 [details] [review]
Patch - remove CREATE USER when koha-create --use-db

-    if [ "$op" = use ]
-    then
-        mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <<eof
-CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
-CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
-GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
-FLUSH PRIVILEGES;
-eof
-    fi #`
-

This is not enough, as the DB is still being created. Look at my previous comment
Comment 4 Yarik Dot 2015-08-11 11:43:59 UTC
(In reply to Tomás Cohen Arazi from comment #2)
> 
> I think the behaviour should be:
> 
> - If the user passes DB parameters (user, pass, hostname, dbname), use them
> to configure the instance. This needs more parameters to be added to
> koha-create. hostname should default to 'localhost' if ommited.

There is currently /etc/mysql/koha-common.cnf used right? Why to change this behavior?

If there is nothing defined in here, default client configuration from /etc/mysql/my.cnf is used.

Anyway, I am ok with changing this behaviour if the change is consistent. That means, there won't be 10 places where the database connection can be defined.

> - If some of the new parameters is missing, fallback to what is configured
> in /etc/koha/passwd.

Why? That is why passwdfile is used, isn't it?

> - If some of the relevant parameters is missing, fail loudly.

Agree.

-------

To explain more how we use it:

first# koha-create --request-db
mysql# mysql; CREATE DB ...; GRANT ...;
first# koha-create --populate-db
second# koha-create --use-db --passwdfile ./file

(In reply to Tomás Cohen Arazi from comment #3)
> This is not enough, as the DB is still being created. Look at my previous
> comment

I have just double checked the koha-create script and database is only created when --create is used. It is on line 560 and nowhere else.
Comment 5 Mark Tompsett 2017-06-22 16:45:58 UTC
Is this ready for sign off?
Comment 6 Mark Tompsett 2017-06-22 17:53:59 UTC
Created attachment 64552 [details] [review]
Bug 14533: remove CREATE USER when koha-create --use-db
Comment 7 Mark Tompsett 2017-06-22 17:56:15 UTC
Comment on attachment 41424 [details] [review]
Patch - remove CREATE USER when koha-create --use-db

This was not a 'git bz attach'd patch. Provided one to make testing easier.
Comment 8 Mark Tompsett 2017-06-22 19:29:20 UTC
Created attachment 64554 [details] [review]
Bug 14533: Deal with comment #2
Comment 9 Mark Tompsett 2017-06-22 19:31:03 UTC
Created attachment 64555 [details] [review]
Bug 14533: Deal with comment #2
Comment 10 Lee Jamison 2017-06-28 22:17:33 UTC
Created attachment 64712 [details] [review]
Bug 14533: remove CREATE USER when koha-create --use-db

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Comment 11 Lee Jamison 2017-06-28 22:17:50 UTC
Created attachment 64713 [details] [review]
Bug 14533: Deal with comment #2

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Comment 12 Tomás Cohen Arazi 2017-08-11 17:53:32 UTC
Created attachment 65920 [details] [review]
Bug 14533: remove CREATE USER when koha-create --use-db

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 13 Tomás Cohen Arazi 2017-08-11 17:53:41 UTC
Created attachment 65921 [details] [review]
Bug 14533: Make --use-db display a message if no DB defined

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 14 Jonathan Druart 2017-08-15 15:26:04 UTC
Pushed to master for 17.11, thanks to everybody involved!
Comment 15 Jonathan Druart 2017-08-15 15:35:52 UTC
Congratulation Yarik and thanks for your first patch!
Comment 16 Fridolin Somers 2017-09-29 10:27:22 UTC
Enhancement not pushed to 17.05.x