add another index to SQL Form tables
This commit is contained in:
parent
44e789544a
commit
8129bef2fb
2 changed files with 27 additions and 2 deletions
|
|
@ -22,11 +22,34 @@ my $quiet; # this line required
|
|||
|
||||
my $session = start(); # this line required
|
||||
|
||||
# upgrade functions go here
|
||||
addIndexesToSQLForms($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
||||
#-------------------------------------------------
|
||||
sub addIndexesToSQLForms {
|
||||
my $session = shift;
|
||||
print "\tAdding extra indexes to SQL Forms.\n" unless ($quiet);
|
||||
my $sqlForms = WebGUI::Asset->getRoot($session)->getLineage(['descendants'], {
|
||||
statusToInclude => [qw(pending approved archived)],
|
||||
statesToInclude => [qw(published trash trash-limbo clipboard clipboard-limbo)],
|
||||
returnObjects => 1,
|
||||
includeOnlyClasses => ['WebGUI::Asset::Wobject::SQLForm'],
|
||||
});
|
||||
for my $sqlForm (@$sqlForms) {
|
||||
my $dbLink = WebGUI::DatabaseLink->new($session, $sqlForm->getValue('databaseLinkId'))->db;
|
||||
my $dbh = $dbLink->dbh;
|
||||
$dbh->{PrintError} = 0;
|
||||
eval {
|
||||
# We don't care about failure
|
||||
$dbh->do('CREATE INDEX `recordId_archived` ON ' . $dbh->quote_identifier($sqlForm->get('tableName')) . ' (__recordId, __archived)');
|
||||
};
|
||||
$dbLink->disconnect;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##-------------------------------------------------
|
||||
#sub exampleFunction {
|
||||
# my $session = shift;
|
||||
|
|
|
|||
|
|
@ -1395,6 +1395,7 @@ my $hasPrimaryKey = 0;
|
|||
}
|
||||
|
||||
$dbLink->db->write("alter table $tableName add primary key (__recordId, __revision)");
|
||||
$dbLink->db->write("alter table $tableName add key recordId_archived (__recordId, __archived)");
|
||||
}
|
||||
else {
|
||||
#new table
|
||||
|
|
@ -1409,7 +1410,8 @@ my $hasPrimaryKey = 0;
|
|||
" __deletedBy varchar(22),".
|
||||
" __archived tinyint(1) default 0,".
|
||||
" __revision int(11) not null,".
|
||||
" primary key (__recordId, __revision)".
|
||||
" primary key (__recordId, __revision),".
|
||||
" key recordId_archived (__recordId, __archived)".
|
||||
")");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue