开发者

How do you specify index length when using DBIx::Class?

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.开发者_StackOverflow

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜