[Catalyst] Adding Indexes To MySQL Database Tables in DBIC "result source" or "table classes"

Robert L Cochran cochranb at speakeasy.net
Mon May 12 18:36:57 BST 2008

I have a MySQL version 5 table named languagelist structured like this:

create table languagelist
    lsigntypid varchar(260) NOT NULL,
    lstage varchar(260) NULL,
    lopcl varchar(260) NULL,
    lentdes varchar(260) NULL,
    lmajcat varchar(260) NULL,
    lfld varchar(260) NULL,
    lflsuh varchar(260) NULL,
    lflv varchar(260) NULL,
    lflvd varchar(260) NULL,
    lmemo1 text NULL,
    lremarks1 varchar(260) NULL,
    lremarks2 varchar(260) NULL,
    INDEX (lsigntypid)
) ENGINE = InnoDB;

I (just now) created a DBIC "result source" or "table class" file for
this, following the tutorial at

------------(start of table class code)-----------

package SignTypDB::LanguageList;

use base qw/DBIx::Class/;  

# Load required DBIC stuff
__PACKAGE__->load_components(qw/PK::Auto Core/);
# Set the table name
# Set columns in table
__PACKAGE__->add_columns(qw/lsigntypid lstage lopcl lentdes lmajcat lfld
lflsuh lflv lflvd lmemo1 lremarks1 lremarks2/);

----------(end of table class code) ------

I want to add an index to the table class code above. Following the
example given here: -->

I think I need to append the following code the the table class shown above:

-------------(start of index sub) ---------

sub sqlt_deploy_hook {
   my ($self, $sqlt_table) = @_;

   $sqlt_table->add_index(name => 'idx_name', fields => ['lsigntypid']);


-------------(end of index sub) ---------

Does the above look correct? What does the 'name' above reference in this context? Is it just a name for the index? Should I change it from 'idx_name' to something else?


Bob Cochran
Greenbelt, Maryland, USA

More information about the Catalyst mailing list