| 1 | package DBIO::Sybase::Diff::Column; | ||||||||||||
| 2 | # ABSTRACT: Diff Sybase ASE columns | ||||||||||||
| 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_column_fields); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use DBIO::Sybase::DDL (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | 6 | ▶ | sub diff { | ||||||||||
|
Subroutine
diff: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||
| 12 | 6 | my ($class, $source, $target, $source_tables, $target_tables) = @_; | |||||||||||
| 13 | 6 | ▶ | $source_tables //= {}; | ||||||||||
|
Condition100%2/2
$source_tables //= {}
MC/DC100%1/1
$source_tables //= {}
$source_tables
Truth table100%2/2
A
A= $source_tables
| |||||||||||||
| 14 | 6 | ▶ | $target_tables //= {}; | ||||||||||
|
Condition100%2/2
$target_tables //= {}
MC/DC100%1/1
$target_tables //= {}
$target_tables
Truth table100%2/2
A
A= $target_tables
| |||||||||||||
| 15 | 6 | my @ops; | |||||||||||
| 16 | |||||||||||||
| 17 | 6 | for my $table (sort keys %$target) { | |||||||||||
| 18 | 7 | ▶ | my $s_cols = $source->{$table} // []; | ||||||||||
|
Condition100%2/2
$source->{$table} // []
MC/DC100%1/1
$source->{$table} // []
$source->{$table}
Truth table100%2/2
A
A= $source->{$table}
| |||||||||||||
| 19 | 7 | ▶ | my $t_cols = $target->{$table} // []; | ||||||||||
|
Condition50%1/2
$target->{$table} // []
MC/DC0%0/1
$target->{$table} // []
$target->{$table}
Truth table50%1/2
A
A= $target->{$table}
| |||||||||||||
| 20 | |||||||||||||
| 21 | 7 | my %s_idx = map { $_->{column_name} => $_ } @$s_cols; | |||||||||||
| 22 | 7 | my %t_idx = map { $_->{column_name} => $_ } @$t_cols; | |||||||||||
| 23 | |||||||||||||
| 24 | 7 | for my $name (sort keys %t_idx) { | |||||||||||
| 25 | 9 | ▶ | if (exists $s_idx{$name}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | push @ops, DBIO::Sybase::Diff::Column::Alter->new( | ||||||||||||
| 27 | action => 'alter', | ||||||||||||
| 28 | table => $table, | ||||||||||||
| 29 | from => $s_idx{$name}, | ||||||||||||
| 30 | to => $t_idx{$name}, | ||||||||||||
| 31 | 6 | ▶ | ) if changed_column_fields($s_idx{$name}, $t_idx{$name}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | } | ||||||||||||
| 33 | else { | ||||||||||||
| 34 | push @ops, DBIO::Sybase::Diff::Column::Add->new( | ||||||||||||
| 35 | action => 'add', | ||||||||||||
| 36 | table => $table, | ||||||||||||
| 37 | 3 | col => $t_idx{$name}, | |||||||||||
| 38 | ); | ||||||||||||
| 39 | } | ||||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 7 | for my $name (sort keys %s_idx) { | |||||||||||
| 43 | push @ops, DBIO::Sybase::Diff::Column::Drop->new( | ||||||||||||
| 44 | action => 'drop', | ||||||||||||
| 45 | table => $table, | ||||||||||||
| 46 | col => $s_idx{$name}, | ||||||||||||
| 47 | 8 | ▶ | ) unless exists $t_idx{$name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 6 | return @ops; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | package DBIO::Sybase::Diff::Column::Add; | ||||||||||||
| 55 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 56 | |||||||||||||
| 57 | 2 | __PACKAGE__->mk_diff_accessors(qw(table col)); | |||||||||||
| 58 | |||||||||||||
| 59 | 3 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 3 | my $self = shift; | |||||||||||
| 61 | sprintf 'ALTER TABLE %s ADD %s %s', | ||||||||||||
| 62 | 3 | $self->table, $self->col->{column_name}, $self->col->{data_type}; | |||||||||||
| 63 | } | ||||||||||||
| 64 | 3 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
| |||||||||||||
| 65 | 3 | my $self = shift; | |||||||||||
| 66 | 3 | "ALTER TABLE $self->{table} ADD $self->{col}{column_name}"; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | package DBIO::Sybase::Diff::Column::Alter; | ||||||||||||
| 70 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 71 | |||||||||||||
| 72 | 2 | __PACKAGE__->mk_diff_accessors(qw(table from to)); | |||||||||||
| 73 | |||||||||||||
| 74 | 1 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=2 SCAR=7.0
| |||||||||||||
| 75 | 1 | my $self = shift; | |||||||||||
| 76 | 1 | my $tbl = $self->table; | |||||||||||
| 77 | 1 | my $col_name = $self->to->{column_name}; | |||||||||||
| 78 | 1 | my $type = $self->to->{data_type}; | |||||||||||
| 79 | 1 | my $sql = "ALTER TABLE $tbl ALTER COLUMN $col_name $type"; | |||||||||||
| 80 | # Sybase ASE supports NOT NULL and DEFAULT in ALTER COLUMN | ||||||||||||
| 81 | 1 | ▶ | $sql .= ' NOT NULL' if $self->to->{not_null}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 1 | $sql .= DBIO::Sybase::DDL::sybase_default_clause($self->to->{default_value}); | |||||||||||
| 83 | 1 | $sql; | |||||||||||
| 84 | } | ||||||||||||
| 85 | 1 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
| |||||||||||||
| 86 | 1 | my $self = shift; | |||||||||||
| 87 | 1 | "ALTER TABLE $self->{table} ALTER $self->{to}{column_name}"; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | package DBIO::Sybase::Diff::Column::Drop; | ||||||||||||
| 91 | 2 | ▶ | use base 'DBIO::Diff::Op'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 92 | |||||||||||||
| 93 | 2 | __PACKAGE__->mk_diff_accessors(qw(table col)); | |||||||||||
| 94 | |||||||||||||
| 95 | 2 | ▶ | sub as_sql { | ||||||||||
|
Subroutine
as_sql: called CC=1 SCAR=0.0
| |||||||||||||
| 96 | 2 | my $self = shift; | |||||||||||
| 97 | 2 | "ALTER TABLE $self->{table} DROP COLUMN $self->{col}{column_name}"; | |||||||||||
| 98 | } | ||||||||||||
| 99 | 2 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: called CC=1 SCAR=0.0
| |||||||||||||
| 100 | 2 | my $self = shift; | |||||||||||
| 101 | 2 | "ALTER TABLE $self->{table} DROP $self->{col}{column_name}"; | |||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | 2 | 1; | |||||||||||
| 105 | |||||||||||||
| 106 | __END__ | ||||||||||||
| 107 | |||||||||||||
| 108 | =pod | ||||||||||||
| 109 | |||||||||||||
| 110 | =encoding UTF-8 | ||||||||||||
| 111 | |||||||||||||
| 112 | =head1 NAME | ||||||||||||
| 113 | |||||||||||||
| 114 | DBIO::Sybase::Diff::Column - Diff Sybase ASE columns | ||||||||||||
| 115 | |||||||||||||
| 116 | =head1 VERSION | ||||||||||||
| 117 | |||||||||||||
| 118 | version 0.900001 | ||||||||||||
| 119 | |||||||||||||
| 120 | =head1 DESCRIPTION | ||||||||||||
| 121 | |||||||||||||
| 122 | Compares two column sets and generates column-level diff operations. | ||||||||||||
| 123 | |||||||||||||
| 124 | =head1 AUTHOR | ||||||||||||
| 125 | |||||||||||||
| 126 | DBIO & DBIx::Class Authors | ||||||||||||
| 127 | |||||||||||||
| 128 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 129 | |||||||||||||
| 130 | Copyright (C) 2026 DBIO Authors | ||||||||||||
| 131 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||
| 132 | Based on DBIx::Class, heavily modified. | ||||||||||||
| 133 | |||||||||||||
| 134 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 135 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 136 | |||||||||||||
| 137 | =cut | ||||||||||||