| 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 //= {}
MC/DC0%0/1
$target_columns //= {}
$target_columns
Truth table50%1/2
A
A= $target_columns
| |||||||||||||
| 15 | 5 | ▶ | $target_fks //= {}; | ||||||||||
|
Condition50%1/2
$target_fks //= {}
MC/DC0%0/1
$target_fks //= {}
$target_fks
Truth table50%1/2
A
A= $target_fks
| |||||||||||||
| 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
| |||||||||||||
| 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} // []
MC/DC0%0/1
$target_columns->{$name} // []
$target_columns->{$name}
Truth table50%1/2
A
A= $target_columns->{$name}
| |||||||||||||
| 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
| |||||||||||||
| 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 // []
MC/DC0%0/1
$self->columns // []
$self->columns
Truth table50%1/2
A
A= $self->columns
| |||||||||||||
| 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
| |||||||||||||
| 57 | 4 | $def .= DBIO::Sybase::DDL::sybase_default_clause($col->{default_value}); | |||||||||||
| 58 | 4 | ▶ | $def .= ' IDENTITY' if $col->{is_auto_increment}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ||||||||||||