| 1 | package DBIO::Sybase::Diff::Index; | ||||||||||||
| 2 | # ABSTRACT: Diff Sybase ASE indexes | ||||||||||||
| 3 | |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use DBIO::Diff::Compare qw(changed_index_fields); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | |||||||||||||
| 10 | 6 | ▶ | sub diff { | ||||||||||
|
Subroutine
diff: called CC=11 SCAR=24.3
Pod
undocumented
| |||||||||||||
| 11 | 6 | my ($class, $source, $target) = @_; | |||||||||||
| 12 | 6 | ▶ | $source //= {}; | ||||||||||
|
Condition50%1/2
$source //= {}
MC/DC0%0/1
$source //= {}
$source
Truth table50%1/2
A
A= $source
| |||||||||||||
| 13 | 6 | ▶ | $target //= {}; | ||||||||||
|
Condition50%1/2
$target //= {}
MC/DC0%0/1
$target //= {}
$target
Truth table50%1/2
A
A= $target
| |||||||||||||
| 14 | 6 | my @ops; | |||||||||||
| 15 | |||||||||||||
| 16 | 6 | for my $table (sort keys %$target) { | |||||||||||
| 17 | 6 | ▶ | my $s_idx = $source->{$table} // {}; | ||||||||||
|
Condition50%1/2
$source->{$table} // {}
MC/DC0%0/1
$source->{$table} // {}
$source->{$table}
Truth table50%1/2
A
A= $source->{$table}
| |||||||||||||
| 18 | 6 | ▶ | my $t_idx = $target->{$table} // {}; | ||||||||||
|
Condition50%1/2
$target->{$table} // {}
MC/DC0%0/1
$target->{$table} // {}
$target->{$table}
Truth table50%1/2
A
A= $target->{$table}
| |||||||||||||
| 19 | |||||||||||||
| 20 | 6 | for my $name (sort keys %$t_idx) { | |||||||||||
| 21 | 5 | ▶ | if (exists $s_idx->{$name}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | push @ops, DBIO::Sybase::Diff::Index::Alter->new( | ||||||||||||
| 23 | action => 'alter', | ||||||||||||
| 24 | table => $table, | ||||||||||||
| 25 | from => $s_idx->{$name}, | ||||||||||||
| 26 | to => $t_idx->{$name}, | ||||||||||||
| 27 | 2 | ▶ | ) if changed_index_fields($s_idx->{$name}, $t_idx->{$name}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | } | ||||||||||||
| 29 | else { | ||||||||||||
| 30 | push @ops, DBIO::Sybase::Diff::Index::Create->new( | ||||||||||||
| 31 | action => 'create', | ||||||||||||
| 32 | table => $table, | ||||||||||||
| 33 | 3 | idx => $t_idx->{$name}, | |||||||||||
| 34 | ); | ||||||||||||
| 35 | } | ||||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 6 | for my $name (sort keys %$s_idx) { | |||||||||||
| 39 | push @ops, DBIO::Sybase::Diff::Index::Drop->new( | ||||||||||||
| 40 | action => 'drop', | ||||||||||||
| 41 | table => $table, | ||||||||||||
| 42 | idx => $s_idx->{$name}, | ||||||||||||
| 43 | 3 | ▶ | ) unless exists $t_idx->{$name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | } | ||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 6 | return @ops; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | package DBIO::Sybase::Diff::Index::Create; | ||||||||||||
| 51 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 52 | |||||||||||||
| 53 | 2 | __PACKAGE__->mk_diff_accessors(qw(table idx)); | |||||||||||
| 54 | |||||||||||||
| 55 | 3 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=2 SCAR=6.9
| |||||||||||||
| 56 | 3 | my $self = shift; | |||||||||||
| 57 | 3 | my $cols = join(', ', @{$self->idx->{columns}}); | |||||||||||
| 58 | 3 | ▶ | my $unique = $self->idx->{is_unique} ? 'UNIQUE ' : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 3 | "CREATE ${unique}INDEX $self->{idx}{index_name} ON $self->{table} ($cols)"; | |||||||||||
| 60 | } | ||||||||||||
| 61 | 1 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
| |||||||||||||
| 62 | 1 | my $self = shift; | |||||||||||
| 63 | 1 | "CREATE INDEX $self->{idx}{index_name} ON $self->{table}"; | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | package DBIO::Sybase::Diff::Index::Alter; | ||||||||||||
| 67 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | |||||||||||||
| 69 | 2 | __PACKAGE__->mk_diff_accessors(qw(table from to)); | |||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: not called CC=2 SCAR=17.9
| |||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||
| 73 | 0 | my $tbl = $self->table; | |||||||||||
| 74 | 0 | my $cols = join(', ', @{$self->to->{columns}}); | |||||||||||
| 75 | 0 | ▶ | my $unique = $self->to->{is_unique} ? 'UNIQUE ' : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | # DROP and CREATE since Sybase ASE does not support ALTER INDEX | ||||||||||||
| 77 | 0 | "DROP INDEX $tbl.$self->{from}{index_name}; CREATE ${unique}INDEX $self->{to}{index_name} ON $tbl ($cols)"; | |||||||||||
| 78 | } | ||||||||||||
| 79 | 0 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: not called CC=1 SCAR=6.9
| |||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||
| 81 | 0 | "ALTER INDEX $self->{to}{index_name} ON $self->{table}"; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | package DBIO::Sybase::Diff::Index::Drop; | ||||||||||||
| 85 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 86 | |||||||||||||
| 87 | 2 | __PACKAGE__->mk_diff_accessors(qw(table idx)); | |||||||||||
| 88 | |||||||||||||
| 89 | 1 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=1 SCAR=0.0
| |||||||||||||
| 90 | 1 | my $self = shift; | |||||||||||
| 91 | 1 | "DROP INDEX $self->{table}.$self->{idx}{index_name}"; | |||||||||||
| 92 | } | ||||||||||||
| 93 | 0 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: not called CC=1 SCAR=6.9
| |||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||
| 95 | 0 | "DROP INDEX $self->{table}.$self->{idx}{index_name}"; | |||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 2 | 1; | |||||||||||
| 99 | |||||||||||||
| 100 | __END__ | ||||||||||||
| 101 | |||||||||||||
| 102 | =pod | ||||||||||||
| 103 | |||||||||||||
| 104 | =encoding UTF-8 | ||||||||||||
| 105 | |||||||||||||
| 106 | =head1 NAME | ||||||||||||
| 107 | |||||||||||||
| 108 | DBIO::Sybase::Diff::Index - Diff Sybase ASE indexes | ||||||||||||
| 109 | |||||||||||||
| 110 | =head1 VERSION | ||||||||||||
| 111 | |||||||||||||
| 112 | version 0.900001 | ||||||||||||
| 113 | |||||||||||||
| 114 | =head1 DESCRIPTION | ||||||||||||
| 115 | |||||||||||||
| 116 | Compares two index sets and generates index-level diff operations. | ||||||||||||
| 117 | |||||||||||||
| 118 | =head1 AUTHOR | ||||||||||||
| 119 | |||||||||||||
| 120 | DBIO & DBIx::Class Authors | ||||||||||||
| 121 | |||||||||||||
| 122 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 123 | |||||||||||||
| 124 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 125 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||
| 126 | Based on DBIx::Class, heavily modified. | ||||||||||||
| 127 | |||||||||||||
| 128 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 129 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 130 | |||||||||||||
| 131 | =cut | ||||||||||||