[otrs-cvs] otrs/Kernel/System/DB db2.pm, 1.38, 1.39 oracle.pm, 1.40, 1.41
CVS commits notifications of OTRS.org
cvs-log at otrs.org
Tue May 6 22:39:03 GMT 2008
- Previous message: [otrs-cvs] otrs/Kernel/System DB.pm,1.89,1.90
- Next message: [otrs-cvs] otrs/scripts/database otrs-schema.db2.sql, 1.25, 1.26 otrs-schema.maxdb.sql, 1.26, 1.27 otrs-schema.mssql.sql, 1.20, 1.21 otrs-schema.mysql.sql, 1.66, 1.67 otrs-schema.oracle.sql, 1.31, 1.32 otrs-schema.postgresql.sql, 1.64, 1.65 otrs-schema.xml, 1.77, 1.78
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Comments:
Update of /home/cvs/otrs/Kernel/System/DB
In directory lancelot:/tmp/cvs-serv17584/Kernel/System/DB
Modified Files:
db2.pm oracle.pm
Log Message:
Added create and drop of foreign key support and generate no more random names for indexes.
Author: martin
Index: db2.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/DB/db2.pm,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** db2.pm 24 Apr 2008 22:04:12 -0000 1.38
--- db2.pm 6 May 2008 22:38:58 -0000 1.39
***************
*** 275,283 ****
my ( $Self, @Param ) = @_;
! my $SQLStart = '';
! my @SQL = ();
! my @Index = ();
! my $IndexName = ();
! my $Table = '';
for my $Tag (@Param) {
--- 275,286 ----
my ( $Self, @Param ) = @_;
! my $SQLStart = '';
! my @SQL = ();
! my @Index = ();
! my $IndexName = ();
! my $ForeignTable = '';
! my $ReferenceName = '';
! my @Reference = ();
! my $Table = '';
for my $Tag (@Param) {
***************
*** 410,413 ****
--- 413,437 ----
push @Index, $Tag;
}
+ elsif ( $Tag->{Tag} =~ /^((ForeignKey)(Create|Drop))/ ) {
+ my $Method = $Tag->{Tag};
+ if ( $Tag->{ForeignTable} ) {
+ $ForeignTable = $Tag->{ForeignTable};
+ }
+ if ( $Tag->{TagType} eq 'End' ) {
+ for my $Reference (@Reference) {
+ push @SQL, $Self->$Method(
+ LocalTableName => $Table,
+ Local => $Reference->{Local},
+ ForeignTableName => $ForeignTable,
+ Foreign => $Reference->{Foreign},
+ );
+ }
+ $ReferenceName = '';
+ @Reference = ();
+ }
+ }
+ elsif ( $Tag->{Tag} =~ /^(Reference)/ && $Tag->{TagType} eq 'Start' ) {
+ push @Reference, $Tag;
+ }
}
return @SQL;
***************
*** 424,430 ****
}
}
! my $Index = substr( $Param{Name}, 0, 16 );
! if ( length($Index) >= 16 ) {
! $Index .= int( rand(99) );
}
my $SQL = "CREATE INDEX $Index ON $Param{TableName} (";
--- 448,458 ----
}
}
! my $Index = $Param{Name};
! if ( length $Index >= 16 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $Index,
! );
! $Index = substr $Index, 0, 14;
! $Index .= substr $MD5, 0, 2;
}
my $SQL = "CREATE INDEX $Index ON $Param{TableName} (";
***************
*** 457,461 ****
}
}
! my $SQL = 'DROP INDEX ' . $Param{Name};
return ($SQL);
}
--- 485,497 ----
}
}
! my $Index = $Param{Name};
! if ( length $Index >= 16 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $Index,
! );
! $Index = substr $Index, 0, 14;
! $Index .= substr $MD5, 0, 2;
! }
! my $SQL = 'DROP INDEX ' . $Index;
return ($SQL);
}
Author: martin
Index: oracle.pm
===================================================================
RCS file: /home/cvs/otrs/Kernel/System/DB/oracle.pm,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** oracle.pm 24 Apr 2008 22:57:24 -0000 1.40
--- oracle.pm 6 May 2008 22:38:58 -0000 1.41
***************
*** 180,186 ****
# add primary key
my $Constraint = $TableName;
! if ( length($Constraint) > 26 ) {
! $Constraint = substr( $Constraint, 0, 24 );
! $Constraint .= int( rand(99) );
}
if ( $Tag->{PrimaryKey} && $Tag->{PrimaryKey} =~ /true/i ) {
--- 180,189 ----
# add primary key
my $Constraint = $TableName;
! if ( length $Constraint > 30 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $Constraint,
! );
! $Constraint = substr $Constraint, 0, 28;
! $Constraint .= substr $MD5, 0, 2;
}
if ( $Tag->{PrimaryKey} && $Tag->{PrimaryKey} =~ /true/i ) {
***************
*** 232,253 ****
}
$SQL .= ')';
- push @{ $Index{'U_INX_' . $TableName . $Name} }, @Array;
}
push @Return, $SQLStart . $SQL . $SQLEnd, @Return2;
- # add indexs
- for my $Name ( keys %Index ) {
- push(
- @Return,
- $Self->IndexCreate(
- TableName => $TableName,
- Name => $Name,
- Data => $Index{$Name},
- )
- );
- }
-
# add foreign keys
! for my $ForeignKey ( keys %Foreign ) {
my @Array = @{ $Foreign{$ForeignKey} };
for ( 0 .. $#Array ) {
--- 235,243 ----
}
$SQL .= ')';
}
push @Return, $SQLStart . $SQL . $SQLEnd, @Return2;
# add foreign keys
! for my $ForeignKey ( sort keys %Foreign ) {
my @Array = @{ $Foreign{$ForeignKey} };
for ( 0 .. $#Array ) {
***************
*** 261,266 ****
--- 251,275 ----
)
);
+
+ # generate forced index for every FK to do row locking (not table locking)
+ my $IndexName = $TableName . '_' . $Array[$_]->{Local};
+ if ( !$Index{$IndexName} ) {
+ $Index{'FK_' . $IndexName } = [ { Name => $Array[$_]->{Local} } ];
+ }
}
}
+
+ # add indexs
+ for my $Name ( sort keys %Index ) {
+ push(
+ @Return,
+ $Self->IndexCreate(
+ TableName => $TableName,
+ Name => $Name,
+ Data => $Index{$Name},
+ )
+ );
+ }
+
return @Return;
}
***************
*** 287,295 ****
my ( $Self, @Param ) = @_;
! my $SQLStart = '';
! my @SQL = ();
! my @Index = ();
! my $IndexName = ();
! my $Table = '';
for my $Tag (@Param) {
if ( $Tag->{Tag} eq 'TableAlter' && $Tag->{TagType} eq 'Start' ) {
--- 296,307 ----
my ( $Self, @Param ) = @_;
! my $SQLStart = '';
! my @SQL = ();
! my @Index = ();
! my $IndexName = ();
! my $ForeignTable = '';
! my $ReferenceName = '';
! my @Reference = ();
! my $Table = '';
for my $Tag (@Param) {
if ( $Tag->{Tag} eq 'TableAlter' && $Tag->{TagType} eq 'Start' ) {
***************
*** 399,402 ****
--- 411,435 ----
push @Index, $Tag;
}
+ elsif ( $Tag->{Tag} =~ /^((ForeignKey)(Create|Drop))/ ) {
+ my $Method = $Tag->{Tag};
+ if ( $Tag->{ForeignTable} ) {
+ $ForeignTable = $Tag->{ForeignTable};
+ }
+ if ( $Tag->{TagType} eq 'End' ) {
+ for my $Reference (@Reference) {
+ push @SQL, $Self->$Method(
+ LocalTableName => $Table,
+ Local => $Reference->{Local},
+ ForeignTableName => $ForeignTable,
+ Foreign => $Reference->{Foreign},
+ );
+ }
+ $ReferenceName = '';
+ @Reference = ();
+ }
+ }
+ elsif ( $Tag->{Tag} =~ /^(Reference)/ && $Tag->{TagType} eq 'Start' ) {
+ push @Reference, $Tag;
+ }
}
return @SQL;
***************
*** 414,423 ****
}
my $Index = $Param{Name};
! if ( length($Index) > 30 ) {
! $Index = substr( $Index, 0, 28 );
! $Index .= int( rand(99) );
}
my $SQL = "CREATE INDEX $Index ON $Param{TableName} (";
! my @Array = @{ $Param{'Data'} };
for ( 0 .. $#Array ) {
if ( $_ > 0 ) {
--- 447,459 ----
}
my $Index = $Param{Name};
! if ( length $Index > 30 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $Index,
! );
! $Index = substr $Index, 0, 28;
! $Index .= substr $MD5, 0, 2;
}
my $SQL = "CREATE INDEX $Index ON $Param{TableName} (";
! my @Array = @{ $Param{Data} };
for ( 0 .. $#Array ) {
if ( $_ > 0 ) {
***************
*** 447,451 ****
}
}
! my $SQL = 'DROP INDEX ' . $Param{Name};
return ($SQL);
}
--- 483,497 ----
}
}
!
! my $Index = $Param{Name};
! if ( length $Index > 30 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $Index,
! );
! $Index = substr $Index, 0, 28;
! $Index .= substr $MD5, 0, 2;
! }
!
! my $SQL = 'DROP INDEX ' . $Index;
return ($SQL);
}
***************
*** 463,468 ****
my $ForeignKey = "FK_$Param{LocalTableName}_$Param{Local}_$Param{Foreign}";
if ( length($ForeignKey) > 30 ) {
! $ForeignKey = substr( $ForeignKey, 0, 28 );
! $ForeignKey .= int( rand(99) );
}
my $SQL = "ALTER TABLE $Param{LocalTableName} ADD CONSTRAINT $ForeignKey FOREIGN KEY (";
--- 509,517 ----
my $ForeignKey = "FK_$Param{LocalTableName}_$Param{Local}_$Param{Foreign}";
if ( length($ForeignKey) > 30 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $ForeignKey,
! );
! $ForeignKey = substr $ForeignKey, 0, 28;
! $ForeignKey .= substr $MD5, 0, 2;
}
my $SQL = "ALTER TABLE $Param{LocalTableName} ADD CONSTRAINT $ForeignKey FOREIGN KEY (";
***************
*** 478,482 ****
# check needed stuff
! for (qw(TableName Name)) {
if ( !$Param{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
--- 527,531 ----
# check needed stuff
! for (qw(LocalTableName Local ForeignTableName Foreign)) {
if ( !$Param{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
***************
*** 484,488 ****
}
}
! my $SQL = "ALTER TABLE $Param{TableName} DISABLE CONSTRAINT $Param{Name}";
return ($SQL);
}
--- 533,545 ----
}
}
! my $ForeignKey = "FK_$Param{LocalTableName}_$Param{Local}_$Param{Foreign}";
! if ( length($ForeignKey) > 30 ) {
! my $MD5 = $Self->{MainObject}->MD5sum(
! String => $ForeignKey,
! );
! $ForeignKey = substr $ForeignKey, 0, 28;
! $ForeignKey .= substr $MD5, 0, 2;
! }
! my $SQL = "ALTER TABLE $Param{TableName} DROP CONSTRAINT $ForeignKey";
return ($SQL);
}
- Previous message: [otrs-cvs] otrs/Kernel/System DB.pm,1.89,1.90
- Next message: [otrs-cvs] otrs/scripts/database otrs-schema.db2.sql, 1.25, 1.26 otrs-schema.maxdb.sql, 1.26, 1.27 otrs-schema.mssql.sql, 1.20, 1.21 otrs-schema.mysql.sql, 1.66, 1.67 otrs-schema.oracle.sql, 1.31, 1.32 otrs-schema.postgresql.sql, 1.64, 1.65 otrs-schema.xml, 1.77, 1.78
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the cvs-log
mailing list