Bug 6517 - koha-create wants "use database" in DEFAULTSQL
Summary: koha-create wants "use database" in DEFAULTSQL
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Packaging (show other bugs)
Version: master
Hardware: All All
: PATCH-Sent (DO NOT USE) enhancement (vote)
Target Milestone: ---
Assignee: Magnus Enger
QA Contact: Bugs List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-18 15:04 UTC by Magnus Enger
Modified: 2012-10-25 23:09 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Proposed patch (1.35 KB, patch)
2011-06-29 21:36 UTC, Magnus Enger
Details | Diff | Splinter Review
Revised patch (1.61 KB, patch)
2011-06-30 06:51 UTC, Magnus Enger
Details | Diff | Splinter Review
Bug 6517 - [REVISED] koha-create wants "use database" in DEFAULTSQL (1.66 KB, patch)
2011-07-02 21:09 UTC, Chris Cormack
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Enger 2011-06-18 15:04:28 UTC
If koha-create is given the path to a DEFAULTSQL in /etc/koha/koha-sites.conf, it looks like it expects to find a statement similar to this at the top of that file: 

use koha___KOHASITE__;

This piece of the code will then replace __KOHASITE__ with the name of the site being created: 

# Populate the database with default content.
zcat "$DEFAULTSQL" |
sed "s/__KOHASITE__/$name/g" |
mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd"

As far as I can see this means one has to remember to add the use koha___KOHASITE__; to the file whenever a new DEFAULTSQL is created. 

Wouldn't it be easier and less error prone to make mysql use the right database by including the name of the database in the call to mysql? Something like this:

# Populate the database with default content.
zcat "$DEFAULTSQL" |
mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd" $mysqldb
Comment 1 Robin Sheat 2011-06-19 01:58:21 UTC
Did you use "koha-dump-defaults" to produce the default SQL? I think that this should take care of it for you.
Comment 2 Magnus Enger 2011-06-29 11:21:54 UTC
Ah, no I used plain ol' mysqldump. But I think it would be good if it was possible to make a mysqldump on a system not running from the packages and then base installs made with the packages on that.
Comment 3 Robin Sheat 2011-06-29 12:26:50 UTC
You can, use '--all-databases' when running mysqldump (but still provide the database name.)

Keep in mind that part of the script is to replace the name of the instance with the placeholder, so that you can make it refer to itself (perhaps a default title or paths or something) and it'll replace that when it's installed to an instance. So it's still handy if you're in a position to use it.
Comment 4 Robin Sheat 2011-06-29 12:27:48 UTC
oh, --all-databases will put in the exact database name which isn't so good for a template. So your idea is still worthwhile :)
Comment 5 Magnus Enger 2011-06-29 21:36:23 UTC Comment hidden (obsolete)
Comment 6 Sébastien Marie 2011-06-30 06:20:26 UTC
I suggest that the variable $mysqldb should be quoted. There isn't difference in general case, but it is a better practice to quote arguments.
Comment 7 Magnus Enger 2011-06-30 06:51:55 UTC Comment hidden (obsolete)
Comment 8 Chris Cormack 2011-07-02 21:09:05 UTC
Created attachment 4549 [details] [review]
Bug 6517 - [REVISED] koha-create wants "use database" in DEFAULTSQL

The revised patch quotes the variable $mysqldb, as suggested by Frère
Sébastien Marie.

This patch makes sure that pointing DEFAULTSQL in /etc/koha/koha-sites.conf
to any (gzip'ed) file produced by mysqldump works, by adding the name of the
database to the end of the call to mysql, when the specified SQL file is
loaded. Files produced with koha-dump-defaults should still work too.

To test:
- Apply the patch
- Create a new package with build-git-snapshot
- Install the package
- Create an SQL file from an existing installation with mysqldump
- gzip the SQL file
- point DEFAULTSQL to the file in /etc/koha/koha-sites.conf
- create a new site with koha-create --create-db

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Comment 9 Chris Cormack 2011-09-11 22:52:33 UTC
Packaging only bug, please test
Comment 10 Chris Nighswonger 2011-10-26 18:02:20 UTC
The fix for this bug was published in the 3.4.5 release. If you were the reporter of this bug, please take time to verify the fix and update the status of this bug report accordingly. If the bug is fixed to your satisfaction, please close this report.