Subject: | Problem updating enum type |
Date: | Tue, 01 Jan 2013 18:37:50 +0100 |
To: | bug-DBIx-Class-Schema-Loader [...] rt.cpan.org |
From: | "rosenstein [...] gmx.de" <rosenstein [...] gmx.de> |
Hi,
my intention was to remove a few items from an enumeration typed field.
Adjusting the schema itself was not a problem. Afterwards I tried to
update my model. Since I am using Catalyst together with DBIx to update
the model, I used a script provided by Catalyst (which internally uses
DBIx::Schema::Loader). The script is run like this
./script/myapp_create.pl model DB DBIC::Schema MyApp::Schema
create=static use_moose=1 naming=v4
"dbi:mysql:database=<database>;hostname=<host>" <db_user> <db_pw>
After running the script, I always end up with my schema classes not
having the newly added enumeration items. After having a look at the
code that actually reads the column information from the database, I
found the following SQL statement (see
DBIx::Class::Schema::Loader::DBI::mysql.pm; line 233)
SELECT numeric_precision, numeric_scale, column_type, column_default
FROM information_schema.columns
WHERE table_name = ? AND lower(column_name) = ?
The problem seems to be, that the query targets a table which stores
information for the entire server. Therefore if you have multiple
database with the same or a very similar schema (which is true in my
case), the query will return multiple rows for the same column name due
to the fact that all of the them belong to different databases.
Unfortunately the query above does not consider that, so that the actual
row read depends on the order in the result set, which is not defined by
the query itself, so seems to be arbitrary or up to mysql internal behavior.
To overcome the problem, I did a qick fix to filter out the right database
SELECT numeric_precision, numeric_scale, column_type, column_default
FROM information_schema.columns
WHERE table_name = ? AND lower(column_name) = ? AND table_schema =
<database>
For the sake of simplicitly, I hard-coded the database name just to see
whether this solves the issue as it does. So the question is whether I
missed some configuration option to specify the right database. But I do
not think so, because that information is already passed (as commandline
argument as you can see above). So maybe it needs to be specified by the
query explicitely. Unfortunately I am not able to find out how and if
yes from where I can get the database name. Moreover there is a similar
query also ignoring to filter the database in that modul as well (line
360).
Additionally here is some information about the environment I used:
* Ubuntu 11.10
* Perl 5.14.2
* DBIx-Class-Schema-Loader 0.07033
* MySQL Server 5.5.24
So please let me know, whether I did something wrong or this is really a
bug in the mysql-loader code.
Best Regards,
max