Sybase/Diff/Table.pm

filter: Statementstmt 100% 52 / 52 Branchbran 87.5% 7 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 88.2% 75 / 85 CC 12 SCAR 14.8
CC
12
Cov
93%
diff
8.2
as_sql
5.0
BEGIN
1.0
CRAP 4.4
« Sybase/Storage/FreeTDS.pm ↑ Summary Sybase/Deploy.pm »
1 package DBIO::Sybase::Diff::Table;
2 # ABSTRACT: Diff Sybase ASE tables
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use DBIO::Diff::Op ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DBIO::SQL::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use DBIO::Sybase::DDL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 5 ▶sub diff {
Subroutine diff: called CC=8 SCAR=21.1
Pod undocumented
13 5 my ($class, $source, $target, $target_columns, $target_fks) = @_;
14 5 ▶ $target_columns //= {};
Condition50%1/2
$target_columns //= {}
l!l
50
MC/DC0%0/1
$target_columns //= {}
$target_columns
Truth table50%1/2
A
A= $target_columns
Aresult
11
00
15 5 ▶ $target_fks //= {};
Condition50%1/2
$target_fks //= {}
l!l
50
MC/DC0%0/1
$target_fks //= {}
$target_fks
Truth table50%1/2
A
A= $target_fks
Aresult
11
00
16 5 my @ops;
17  
18 5 for my $name (sort keys %$target) {
19 # Existing tables are reconciled column-by-column and index-by-index by
20 # DBIO::Sybase::Diff::Column / ::Index. There is no table-level ALTER op:
21 # Sybase ASE cannot convert a table to a view (or vice versa) in place, so
22 # a kind change is left for a human rather than emitting a broken stub.
23 5 ▶ next if exists $source->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $source->{$name} 2 3 5
24 push @ops, DBIO::Sybase::Diff::Table::Create->new(
25 action => 'create',
26 table => $target->{$name},
27 3 ▶ columns => $target_columns->{$name} // [],
Condition50%1/2
$target_columns->{$name} // []
l!l
30
MC/DC0%0/1
$target_columns->{$name} // []
$target_columns->{$name}
Truth table50%1/2
A
A= $target_columns->{$name}
Aresult
11
00
28 );
29 }
30  
31 5 for my $name (sort keys %$source) {
32 push @ops, DBIO::Sybase::Diff::Table::Drop->new(
33 action => 'drop',
34 table => $source->{$name},
35 4 ▶ ) unless exists $target->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $target->{$name} 2 2 4
36 }
37  
38 5 return @ops;
39 }
40  
41 package DBIO::Sybase::Diff::Table::Create;
42 1 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 __PACKAGE__->mk_diff_accessors(qw(table columns));
45  
46 3 ▶sub as_sql {
Subroutine as_sql: called CC=5 SCAR=16.2
47 3 my $self = shift;
48 3 my $tbl = DBIO::SQL::Util::_quote_ident($self->table->{table_name});
49 3 my @col_defs;
50  
51 3 ▶ my $cols = $self->columns // [];
Condition50%1/2
$self->columns // []
l!l
30
MC/DC0%0/1
$self->columns // []
$self->columns
Truth table50%1/2
A
A= $self->columns
Aresult
11
00
52 3 for my $col (@$cols) {
53 4 my $type = DBIO::Sybase::DDL::sybase_column_type($col->{data_type});
54 my $def = sprintf ' %s %s',
55 4 DBIO::SQL::Util::_quote_ident($col->{column_name}), $type;
56 4 ▶ $def .= ' NOT NULL' if $col->{not_null};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"not_null"} 4 0 4
57 4 $def .= DBIO::Sybase::DDL::sybase_default_clause($col->{default_value});
58 4 ▶ $def .= ' IDENTITY' if $col->{is_auto_increment};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"is_auto_increment"} 1 3 4
59 4 push @col_defs, $def;
60 }
61  
62 3 sprintf "CREATE TABLE %s (\n%s\n);", $tbl, join(",\n", @col_defs);
63 }
64 2 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
65 2 my $self = shift;
66 2 "CREATE TABLE " . $self->table->{table_name};
67 }
68  
69 package DBIO::Sybase::Diff::Table::Drop;
70 1 ▶use base 'DBIO::Diff::Op';
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 1 __PACKAGE__->mk_diff_accessors(qw(table));
73  
74 2 ▶sub as_sql {
Subroutine as_sql: called CC=1 SCAR=0.0
75 2 my $self = shift;
76 2 "DROP TABLE " . $self->table->{table_name};
77 }
78 2 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
79 2 my $self = shift;
80 2 "DROP TABLE " . $self->table->{table_name};
81 }
82  
83 1 1;
84  
85 __END__
86  
87 =pod
88  
89 =encoding UTF-8
90  
91 =head1 NAME
92  
93 DBIO::Sybase::Diff::Table - Diff Sybase ASE tables
94  
95 =head1 VERSION
96  
97 version 0.900001
98  
99 =head1 DESCRIPTION
100  
101 Compares two table sets and generates table-level diff operations.
102  
103 =head1 AUTHOR
104  
105 DBIO & DBIx::Class Authors
106  
107 =head1 COPYRIGHT AND LICENSE
108  
109 Copyright (C) 2026 DBIO Authors
110 Portions Copyright (C) 2005-2025 DBIx::Class Authors
111 Based on DBIx::Class, heavily modified.
112  
113 This is free software; you can redistribute it and/or modify it under
114 the same terms as the Perl 5 programming language system itself.
115  
116 =cut
« Sybase/Storage/FreeTDS.pm ↑ Summary Sybase/Deploy.pm »