/usr/share/perl5/Alzabo/RDBMSRules.pm is in libalzabo-perl 0.92-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 | package Alzabo::RDBMSRules;
use strict;
use vars qw($VERSION);
use Alzabo::Exceptions ( abbr => [ 'recreate_table_exception' ] );
use Class::Factory::Util;
use Params::Validate qw( validate validate_pos );
Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } );
$VERSION = 2.0;
1;
sub new
{
shift;
my %p = @_;
eval "use Alzabo::RDBMSRules::$p{rdbms};";
Alzabo::Exception::Eval->throw( error => $@ ) if $@;
return "Alzabo::RDBMSRules::$p{rdbms}"->new(@_);
}
sub available { __PACKAGE__->subclasses }
# validation
sub validate_schema_name
{
shift()->_virtual;
}
sub validate_table_name
{
shift()->_virtual;
}
sub validate_column_name
{
shift()->_virtual;
}
sub validate_column_type
{
shift()->_virtual;
}
sub validate_column_length
{
shift()->_virtual;
}
sub validate_table_attribute
{
shift()->_virtual;
}
sub validate_column_attribute
{
shift()->_virtual;
}
sub validate_primary_key
{
shift()->_virtual;
}
sub validate_sequenced_attribute
{
shift()->_virtual;
}
sub validate_index
{
shift()->_virtual;
}
sub type_is_numeric
{
my $self = shift;
my $col = shift;
return $self->type_is_integer($col) || $self->type_is_floating_point($col);
}
sub type_is_integer
{
shift()->_virtual;
}
sub type_is_floating_point
{
shift()->_virtual;
}
sub type_is_character
{
shift()->_virtual;
}
sub type_is_date
{
shift()->_virtual;
}
sub type_is_datetime
{
shift()->_virtual;
}
sub type_is_time
{
shift()->_virtual;
}
sub type_is_time_interval
{
shift()->_virtual;
}
sub type_is_blob
{
shift()->_virtual;
}
sub blob_type
{
shift()->virtual;
}
# feature probing
sub column_types
{
shift()->_virtual;
}
sub feature
{
return 0;
}
sub quote_identifiers { 0 }
sub quote_identifiers_character { '' }
sub schema_attributes
{
shift()->_virtual;
}
sub table_attributes
{
shift()->_virtual;
}
sub column_attributes
{
shift()->_virtual;
}
sub schema_sql
{
my $self = shift;
validate_pos( @_, { isa => 'Alzabo::Schema' } );
my $schema = shift;
my @sql;
local $self->{state};
foreach my $t ( $schema->tables )
{
push @sql, $self->table_sql($t);
}
return @sql, @{ $self->{state}{deferred_sql} || [] };
}
sub table_sql
{
shift()->_virtual;
}
sub column_sql
{
shift()->_virtual;
}
sub index_sql
{
my $self = shift;
my $index = shift;
my $index_name = $index->id;
$index_name = $self->quote_identifiers_character . $index_name . $self->quote_identifiers_character;
my $sql = 'CREATE';
$sql .= ' UNIQUE' if $index->unique;
$sql .= " INDEX $index_name ON ";
$sql .= $self->quote_identifiers_character;
$sql .= $index->table->name;
$sql .= $self->quote_identifiers_character;
$sql .= ' ( ';
if ( defined $index->function )
{
$sql .= $index->function;
}
else
{
$sql .=
( join ', ',
map { $self->quote_identifiers_character . $_->name . $self->quote_identifiers_character }
$index->columns
);
}
$sql .= ' )';
return $sql;
}
sub foreign_key_sql
{
shift()->_virtual;
}
sub drop_table_sql
{
my $self = shift;
my $name = shift->name;
$name = $self->quote_identifiers_character . $name . $self->quote_identifiers_character;
return "DROP TABLE $name";
}
sub drop_column_sql
{
shift()->_virtual;
}
sub drop_index_sql
{
shift()->_virtual;
}
sub drop_foreign_key_sql
{
shift()->_virtual;
}
sub column_sql_add
{
shift()->_virtual;
}
sub column_sql_diff
{
shift()->_virtual;
}
sub index_sql_diff
{
my $self = shift;
validate( @_, { new => { isa => 'Alzabo::Index' },
old => { isa => 'Alzabo::Index' } } );
my %p = @_;
my $new_sql = $self->index_sql($p{new});
my @sql;
if ( $new_sql ne $self->index_sql($p{old}) )
{
push @sql, $self->drop_index_sql( $p{old}, $p{new}->table->name );
push @sql, $new_sql;
}
return @sql;
}
sub alter_primary_key_sql
{
shift()->_virtual;
}
sub can_alter_table_name
{
1;
}
sub can_alter_column_name
{
1;
}
sub alter_table_name_sql
{
shift()->_virtual;
}
sub alter_column_name_sql
{
shift()->_virtual;
}
sub recreate_table_sql
{
shift()->_virtual;
}
=pod
sub reverse_engineer
{
my $self = shift;
my $schema = shift;
my $dbh = $schema->driver->handle;
foreach my $table ( $dbh->tables )
{
my $t = $schema->make_table( name => $table );
$self->reverse_engineer_table($t);
}
}
sub reverse_engineer_table
{
my $self = shift;
my $table = shift;
my $dbh = $table->schema->driver->handle;
my $sth = $dbh->column_info( undef, $table->schema->name, $table->name, undef );
while ( my $col_info = $sth->fetchrow_hashref )
{
use Data::Dumper; warn Dumper $col_info;
my %attr = ( name => $col_info->{COLUMN_NAME},
type => $col_info->{TYPE_NAME},
nullable => $col_info->{NULLABLE} ? 1 : 0,
);
$attr{size} =
$col_info->{COLUMN_SIZE} if $col_info->{COLUMN_SIZE};
$attr{precision} =
$col_info->{DECIMAL_DIGITS} if $col_info->{DECIMAL_DIGITS};
$attr{default} =
$col_info->{COLUMN_DEF} if defined $col_info->{COLUMN_DEF};
$attr{comment} =
$col_info->{REMARKS} if defined $col_info->{REMARKS};
$table->make_column(%attr);
}
$self->reverse_engineer_table_primary_key($table);
}
sub reverse_engineer_table_primary_key
{
my $self = shift;
my $table = shift;
my $dbh = $table->schema->driver->handle;
my $sth = $dbh->column_info( undef, $table->schema->name, $table->name );
while ( my $pk_info = $sth->fetchrow_hashref )
{
$table->add_primary_key( $table->column( $pk_info->{COLUMN_NAME} ) );
}
}
=cut
sub rules_id
{
shift()->_virtual;
}
sub schema_sql_diff
{
my $self = shift;
validate( @_, { new => { isa => 'Alzabo::Schema' },
old => { isa => 'Alzabo::Schema' } } );
my %p = @_;
local $self->{state};
my @sql;
my %changed_name;
foreach my $new_t ( $p{new}->tables )
{
# When syncing against an existing schema, the table may be
# present with its new name.
my $old_t;
if ( defined $new_t->former_name )
{
$old_t = eval { $p{old}->table( $new_t->former_name ) };
}
$old_t ||= eval { $p{old}->table( $new_t->name ) };
if ($old_t)
{
if ( $old_t->name ne $new_t->name )
{
$changed_name{ $old_t->name } = 1;
if ( $self->can_alter_table_name )
{
push @sql, $self->alter_table_name_sql($new_t);
}
else
{
push @sql, $self->recreate_table_sql( new => $new_t,
old => $old_t,
);
push @sql, $self->rename_sequences( new => $new_t,
old => $old_t,
);
# no need to do more because table will be
# recreated from scratch
next;
}
}
push @sql,
eval { $self->table_sql_diff( new => $new_t,
old => $old_t ) };
if ( my $e = Exception::Class->caught('Alzabo::Exception::RDBMSRules::RecreateTable' ) )
{
push @sql, $self->recreate_table_sql( new => $new_t,
old => $old_t,
);
}
elsif ( $e = $@ )
{
die $e;
}
}
else
{
push @sql, $self->table_sql($new_t);
foreach my $fk ( $new_t->all_foreign_keys )
{
push @{ $self->{state}{deferred_sql} }, $self->foreign_key_sql($fk);
}
}
}
foreach my $old_t ( $p{old}->tables )
{
unless ( $changed_name{ $old_t->name } ||
eval { $p{new}->table( $old_t->name ) } )
{
push @sql, $self->drop_table_sql($old_t);
}
}
return @sql, @{ $self->{state}{deferred_sql} || [] };
}
sub table_sql_diff
{
my $self = shift;
validate( @_, { new => { isa => 'Alzabo::Table' },
old => { isa => 'Alzabo::Table' } } );
my %p = @_;
my @sql;
foreach my $old_i ( $p{old}->indexes )
{
unless ( eval { $p{new}->index( $old_i->id ) } )
{
push @sql, $self->drop_index_sql($old_i, $p{new}->name)
if eval { $p{new}->columns( map { $_->name } $old_i->columns ) } && ! $@;
}
}
my %changed_name;
foreach my $new_c ( $p{new}->columns )
{
$changed_name{ $new_c->former_name } = 1
if defined $new_c->former_name && $new_c->former_name ne $new_c->name;
}
foreach my $old_c ( $p{old}->columns )
{
unless ( $changed_name{ $old_c->name } ||
( my $new_c = eval { $p{new}->column( $old_c->name ) } )
)
{
push @sql, $self->drop_column_sql( new_table => $p{new},
old => $old_c );
}
}
foreach my $new_c ( $p{new}->columns )
{
# When syncing against an existing schema, the column may be
# present with its new name.
my $old_c;
if ( defined $new_c->former_name )
{
$old_c = eval { $p{old}->column( $new_c->former_name ) };
}
$old_c ||= eval { $p{old}->column( $new_c->name ) };
if ($old_c)
{
if ( $old_c->name ne $new_c->name )
{
if ( $self->can_alter_column_name )
{
push @sql, $self->alter_column_name_sql($new_c);
}
else
{
# no need to do more because table will be
# recreated from scratch
recreate_table_exception();
}
}
push @sql, $self->column_sql_diff( new => $new_c,
old => $old_c,
);
}
else
{
push @sql, $self->column_sql_add($new_c);
}
}
foreach my $new_i ( $p{new}->indexes )
{
if ( my $old_i = eval { $p{old}->index( $new_i->id ) } )
{
push @sql, $self->index_sql_diff( new => $new_i,
old => $old_i );
}
else
{
push @sql, $self->index_sql($new_i)
}
}
foreach my $new_fk ( $p{new}->all_foreign_keys )
{
unless ( grep { $new_fk->id eq $_->id } $p{old}->all_foreign_keys )
{
push @{ $self->{state}{deferred_sql} }, $self->foreign_key_sql($new_fk)
}
}
foreach my $old_fk ( $p{old}->all_foreign_keys )
{
unless ( grep { $old_fk->id eq $_->id } $p{new}->all_foreign_keys )
{
push @sql, $self->drop_foreign_key_sql($old_fk);
}
}
my $pk_changed;
foreach my $old_pk ( $p{old}->primary_key )
{
next if $changed_name{ $old_pk->name };
my $new_col = eval { $p{new}->column( $old_pk->name ) };
unless ( $new_col && $new_col->is_primary_key )
{
push @sql, $self->alter_primary_key_sql( new => $p{new},
old => $p{old} );
$pk_changed = 1;
last;
}
}
unless ($pk_changed)
{
foreach my $new_pk ( $p{new}->primary_key )
{
my $old_col = eval { $p{old}->column( $new_pk->name ) };
next if $new_pk->former_name && $changed_name{ $new_pk->former_name };
unless ( $old_col && $old_col->is_primary_key )
{
push @sql, $self->alter_primary_key_sql( new => $p{new},
old => $p{old} );
last;
}
}
}
my $alter_attributes;
foreach my $new_att ( $p{new}->attributes )
{
unless ( $p{old}->has_attribute( attribute => $new_att, case_sensitive => 1 ) )
{
$alter_attributes = 1;
push @sql, $self->alter_table_attributes_sql( new => $p{new},
old => $p{old},
);
last;
}
}
unless ($alter_attributes)
{
foreach my $old_att ( $p{old}->attributes )
{
unless ( $p{new}->has_attribute( attribute => $old_att, case_sensitive => 1 ) )
{
$alter_attributes = 1;
push @sql, $self->alter_table_attributes_sql( new => $p{new},
old => $p{old},
);
last;
}
}
}
return @sql;
}
sub _virtual
{
my $self = shift;
my $sub = (caller(1))[3];
Alzabo::Exception::VirtualMethod->throw( error =>
"$sub is a virtual method and must be subclassed in " . ref $self );
}
__END__
=head1 NAME
Alzabo::RDBMSRules - Base class for Alzabo RDBMS rulesets
=head1 SYNOPSIS
use Alzabo::RDBMSRules;
my $rules = Alzabo::RDBMSRules( rules => 'MySQL' );
=head1 DESCRIPTION
This class is the base class for all C<Alzabo::RDBMSRules> modules.
To instantiate a subclass call this class's C<new()> method. See the
L<SUBCLASSING Alzabo::RDBMSRules> section for information on how to
make a ruleset for the RDBMS of your choice.
=head1 METHODS
=head2 available
A list of names representing the available C<Alzabo::RDBMSRules>
subclasses. Any one of these names would be appropriate as the
"rdbms" parameter for the L<C<< Alzabo::RDBMSRules->new()
>>|Alzabo::RDBMSRules/new> method.
=head2 new
The constructor always accepts one parameter, "rdbms", which is the
name of the RDBMS to be used.
Some subclasses may accept additional values.
The constructor returns a new C<Alzabo::RDBMSRules> object of the
appropriate subclass.
Throws: L<C<Alzabo::Exception::Eval>|Alzabo::Exceptions>
=head2 schema_sql (C<Alzabo::Create::Schema> object)
Returns a list of SQL statements which would create the given schema.
=head2 index_sql (C<Alzabo::Create::Index> object)
Returns a list of SQL statements to create the specified index.
=head2 drop_table_sql (C<Alzabo::Create::Table> object)
Returns a list of SQL statements to drop the specified table.
=head2 drop_index_sql (C<Alzabo::Create::Index> object)
Returns a list of SQL statements to drop the specified index.
=head2 schema_sql_diff
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Schema> object
=item * old => C<Alzabo::Create::Schema> object
=back
This method compares the two schema objects and returns an array of
SQL statements which turn the "old" schema into the "new" one.
=head2 table_sql_diff
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Table> object
=item * old => C<Alzabo::Create::Table> object
=back
This method compares the two table objects and returns an array of
SQL statements which turn the "old" table into the "new" one.
=head2 type_is_numeric (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is numeric
(integer or floating point).
=head2 quote_identifiers
Returns true or false to indicate whether or not the generated DDL SQL
statements should have their identifiers quoted or not. This may be
overridden by subclasses. It defaults to false.
=head2 can_alter_table_name
If this is true, then when syncing a schema, the object will call
C<alter_table_name_sql()> to change the table's name. Otherwise it
will call C<recreate_table_sql()>.
=head2 can_alter_column_name
If this is true, then when syncing a schema, the object will call
C<alter_column_name_sql()> to change the table's name. Otherwise it
will call C<recreate_table_sql()>.
=head2 Virtual Methods
The following methods are not implemented in the C<Alzabo::RDBMSRules>
class itself and must be implemented in its subclasses.
=head2 column_types
Returns a list of valid column types.
=head2 feature ($feature)
Given a string defining a feature, this method indicates whether or
not the given RDBMS supports that feature. By default, this method
always returns false unless overridden in the subclass.
Features that may be asked for:
=over 4
=item * extended_column_types
Column types that must be input directly from a user, as opposed to
being chosen from a list. MySQL's ENUM and SET types are examples of
such types.
=item * index_column_prefixes
MySQL supports the notion of column prefixes in indexes, allowing you
to index only a portion of a large text column.
=item * fulltext_indexes
This should be self-explanatory.
=item * functional_indexes
Indexes on functions, as supported by PostgreSQL.
=back
=head2 validate_schema_name (C<Alzabo::Schema> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the schema's name is not valid.
=head2 validate_table_name (C<Alzabo::Create::Table> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the table's name is not valid.
=head2 validate_column_name (C<Alzabo::Create::Column> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the column's name is not valid.
=head2 validate_column_type ($type_as_string)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the type is not valid.
This method returns a canonized version of the type.
=head2 validate_column_length (C<Alzabo::Create::Column> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the length or precision is not valid for the given column.
=head2 validate_column_attribute
This method takes two parameters:
=over 4
=item * column => C<Alzabo::Create::Column> object
=item * attribute => $attribute
=back
This method is a bit different from the others in that it takes an
existing column object and a B<potential> attribute.
It throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the attribute is is not valid for the column.
=head2 validate_primary_key (C<Alzabo::Create::Column> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the column is not a valid primary key for its table.
=head2 validate_sequenced_attribute (C<Alzabo::Create::Column> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the column cannot be sequenced.
=head2 validate_index (C<Alzabo::Create::Index> object)
Throws an L<C<Alzabo::Exception::RDBMSRules>|Alzabo::Exceptions> if
the index is not valid.
=head2 table_sql (C<Alzabo::Create::Table> object)
Returns an array of SQL statements to create the specified table.
=head2 column_sql (C<Alzabo::Create::Column> object)
Returns an array of SQL statements to create the specified column.
=head2 foreign_key_sql (C<Alzabo::Create::ForeignKey> object)
Returns an array of SQL statements to create the specified foreign
key.
=head2 drop_column_sql (C<Alzabo::Create::Column> object)
Returns an array of SQL statements to drop the specified column.
=head2 drop_foreign_key_sql (C<Alzabo::Create::ForeignKey> object)
Returns an array of SQL statements to drop the specified foreign key.
=head2 column_sql_add (C<Alzabo::Create::Column> object)
Returns an array of SQL statements to add the specified column.
=head2 column_sql_diff
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Column> object
=item * old => C<Alzabo::Create::Column> object
=back
This method compares the two table objects and returns an array of
SQL statements which turn the "old" table into the "new" one.
=head2 index_sql_diff
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Index> object
=item * old => C<Alzabo::Create::Index> object
=back
This method compares the two index objects and returns an array of
SQL statements which turn the "old" index into the "new" one.
=head2 alter_primary_key_sql
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Table> object
=item * old => C<Alzabo::Create::Table> object
=back
This method compares the two table objects and returns an array of SQL
statements which alter the "old" one's primary key to match the "new"
one's.
=head2 alter_table_name_sql (C<Alzabo::Create::Table> object)
Given a table, this method is expected to change the table's name from
C<< $table->former_name >> to C<< $table->name >>. This will only be
called if the rules object returns true for C<can_alter_table_name()>.
=head2 alter_column_name_sql (C<Alzabo::Create::Table> object)
Given a column, this method is expected to change the table's name
from C<< $column->former_name >> to C<< $column->name >>. This will
only be called if the rules object returns true for
C<can_alter_column_name()>.
=head2 recreate_table_sql
This method takes two parameters:
=over 4
=item * new => C<Alzabo::Create::Table> object
=item * old => C<Alzabo::Create::Table> object
=back
This method is expected to drop the old table and create the new one.
However, it B<must> preserve all the data stored in the old table,
excluding data in columns that are being dropped. Additionally, if
there are sequences associated with columns in the old table, they
should not be dropped.
This method will only be called if either C<can_alter_table_name()> or
C<can_alter_column_name()> return false.
=head2 reverse_engineer (C<Alzabo::Create::Schema> object)
Given a schema object (which presumably has no tables), this method
uses the schema's L<C<Alzabo::Driver>|Alzabo::Driver> object to
connect to an existing database and reverse engineer it into the
appropriate Alzabo objects.
=head2 type_is_integer (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is an integer
type.
=head2 type_is_floating_point (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a floating
point type.
=head2 type_is_character (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a character
type. This is defined as any type which is defined to store text,
regardless of length.
=head2 type_is_date (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a date type.
This is B<not> true for datetime types.
=head2 type_is_datetime (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a datetime
type. This is B<not> true for date types.
=head2 type_is_time (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a time type.
This is B<not> true for datetime types.
=head2 type_is_time_interval (C<Alzabo::Column> object)
Returns a boolean indicating whether or not the column is a time
interval type.
=head1 SUBCLASSING Alzabo::RDBMSRules
To create a subclass of C<Alzabo::RDBMSRules> for your particular
RDBMS is fairly simple.
Here's a sample header to the module using a fictional RDBMS called
FooDB:
package Alzabo::RDBMSRules::FooDB;
use strict;
use vars qw($VERSION);
use Alzabo::RDBMSRules;
use base qw(Alzabo::RDBMSRules);
The next step is to implement a C<new()> method and the methods listed
under the section L<Virtual Methods>. The new method should look a
bit like this:
1: sub new
2: {
3: my $proto = shift;
4: my $class = ref $proto || $proto;
5: my %p = @_;
6:
7: my $self = bless {}, $self;
8:
9: return $self;
10: }
The hash %p contains any values passed to the
L<C<Alzabo::RDBMSRules-E<gt>new>|Alzabo::RDBMSRules/new> method by its
caller.
Lines 1-7 should probably be copied verbatim into your own C<new>
method. Line 5 can be deleted if you don't need to look at the
parameters.
The rest of your module should simply implement the methods listed
under the L<Virtual Methods> section of this documentation.
Look at the included C<Alzabo::RDBMSRules> subclasses for examples.
Feel free to contact me for further help if you get stuck. Please
tell me what database you're attempting to implement, and include the
code you've written so far.
=head1 AUTHOR
Dave Rolsky, <dave@urth.org>
=cut
|