0

I'm using DBIx::Class and am using the sqlt_deploy_hook to:

sub {
    my ($self, $sqlt_table) = @_;
    $sqlt_table->add_index(name => 'indexes', fields => [keys %for_indexing]);
}

Some of the columns I want to index are of type text, or are varchars > 255 length. MySQL doesn't like text indexes unless you specify them with a length, like this:

index (long_field(996))

But looking at SQL::Translator::Schema::Table (which has the add_index method) and Index, I see no way to specify the length.

add_index(name => 'indexes', fields => ['long_field'])

generates this SQL:

INDEX `indexes` (`long_field`)

and this:

add_index(name => 'indexes', fields => ['long_field(996)'])

generates this SQL:

INDEX `indexes` (`long_field(996)`)

which doesn't work, since there is not column with that name.

Up to now I've gotten around this by simply not indexing my text columns. However I'm now trying to use DBIx::Class::DeploymentHandler which is converting my long varchars to text columns when I "install", and I really need those varchar columns indexed.

What can I do?

1
  • The problem is that SQL::Translator, which DBICDH uses, needs to know a mysql version to generate more accurate sql (IE not mangle your column types so much). In the constructor for your DeploymentHandler include: "sql_translator_args => { mysql_version => '5.0.3' }" Commented Jul 28, 2011 at 14:28

2 Answers 2

3

This is a drop late, but the latest version of SQL::Translator (1.64) now has direct support for this, via passing in a hashref for the field consisting of { name => $name, prefix_length => $num } (which would be { name => 'long_field', prefix_length => 996 } in the example from OP.

1

I'm sorry, SQL::Translator simply doesn't understand how to produce index declarations with lengths, which means that DBIC deploy and DBICDH can't do it either, since they do their work through SQLT. If you want to come by irc.perl.org #sql-translator and discuss how this feature would work and what the interface would be, it might get added, but currently it's not possible.

As for your assertion that DBICDH is "converting my long varchars to text columns", there's something very wrong with that; it's not desired behavior for DBICDH. Please post a new question about that issue, showing what you're doing, or bring it to irc.perl.org #dbix-class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.